From 42ffd59ad6758721d37eb7fe8b34b6d084db2010 Mon Sep 17 00:00:00 2001 From: Andros Fenollosa Date: Sat, 13 Mar 2021 10:39:24 +0100 Subject: [PATCH] Add comments --- apps/back/consumers.py | 3 +- .../front/templates/partials/blog/single.html | 28 +++++++++++++++---- 2 files changed, 25 insertions(+), 6 deletions(-) diff --git a/apps/back/consumers.py b/apps/back/consumers.py index cb6a15d..aaba870 100644 --- a/apps/back/consumers.py +++ b/apps/back/consumers.py @@ -1,7 +1,7 @@ import json from channels.generic.websocket import WebsocketConsumer from django.template.loader import render_to_string -from apps.back.models import Post +from apps.back.models import Post, Comment class BlogConsumer(WebsocketConsumer): @@ -31,6 +31,7 @@ class BlogConsumer(WebsocketConsumer): if template == "partials/blog/single.html": data["post"] = Post.objects.get(pk=data['id']) + data["comments"] = Comment.objects.filter(post__id=data['id']).all() # Send message to WebSocket self.send( diff --git a/apps/front/templates/partials/blog/single.html b/apps/front/templates/partials/blog/single.html index 3d21b39..d806c2c 100644 --- a/apps/front/templates/partials/blog/single.html +++ b/apps/front/templates/partials/blog/single.html @@ -1,5 +1,23 @@ -
-

{{ post.title }}

-

{{ post.author }}

-
{{ post.content }}
-
\ No newline at end of file +
+
+

{{ post.title }}

+

{{ post.author }}

+
{{ post.content }}
+
+
+
+

Comments

+ {% for comment in comments %} +
+
+ +
+
+

{{ comment.name }}

+

{{ comment.body }}

+
+
+
+ {% endfor %} +
+
\ No newline at end of file