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