Add comments

This commit is contained in:
Andros Fenollosa 2021-03-13 10:39:24 +01:00
parent 5e4791a240
commit 42ffd59ad6
2 changed files with 25 additions and 6 deletions

View File

@ -1,7 +1,7 @@
import json import json
from channels.generic.websocket import WebsocketConsumer from channels.generic.websocket import WebsocketConsumer
from django.template.loader import render_to_string from django.template.loader import render_to_string
from apps.back.models import Post from apps.back.models import Post, Comment
class BlogConsumer(WebsocketConsumer): class BlogConsumer(WebsocketConsumer):
@ -31,6 +31,7 @@ class BlogConsumer(WebsocketConsumer):
if template == "partials/blog/single.html": if template == "partials/blog/single.html":
data["post"] = Post.objects.get(pk=data['id']) data["post"] = Post.objects.get(pk=data['id'])
data["comments"] = Comment.objects.filter(post__id=data['id']).all()
# Send message to WebSocket # Send message to WebSocket
self.send( self.send(

View File

@ -1,5 +1,23 @@
<article> <div class="container grid-md">
<h1>{{ post.title }}</h1> <article>
<h2>{{ post.author }}</h2> <h1>{{ post.title }}</h1>
<div>{{ post.content }}</div> <h2>{{ post.author }}</h2>
</article> <div>{{ post.content }}</div>
</article>
<section id="comments">
<hr>
<h3>Comments</h3>
{% for comment in comments %}
<div class="tile">
<div class="tile-icon">
<i class="icon icon-file centered"></i>
</div>
<div class="tile-content">
<p class="tile-title">{{ comment.name }}</p>
<p class="tile-subtitle">{{ comment.body }}</p>
</div>
</div>
<hr>
{% endfor %}
</section>
</div>