Added forum_post to Reply model, updated views.py of forum app

parent 1613af84
......@@ -8,8 +8,8 @@ class ForumPostAdmin(admin.ModelAdmin):
class ReplyAdmin(admin.ModelAdmin):
model = Reply
list_display = ("body", "author", "pub_datetime",)
search_field = ("body", "author", "pub_datetime",)
list_display = ("body", "author", "pub_datetime", "forum_post")
search_field = ("body", "author", "pub_datetime", "forum_post")
admin.site.register(ForumPost, ForumPostAdmin)
admin.site.register(Reply, ReplyAdmin)
# Generated by Django 3.2 on 2023-03-06 04:43
from django.db import migrations, models
import django.db.models.deletion
class Migration(migrations.Migration):
dependencies = [
('forum', '0001_initial'),
]
operations = [
migrations.AddField(
model_name='reply',
name='forum_post',
field=models.ForeignKey(null=True, on_delete=django.db.models.deletion.CASCADE, to='forum.forumpost'),
),
]
......@@ -13,6 +13,7 @@ class Reply(models.Model):
body = models.TextField()
author = models.ForeignKey('dashboard.WidgetUser', on_delete=models.CASCADE)
pub_datetime = models.DateTimeField()
forum_post = models.ForeignKey('ForumPost', on_delete=models.CASCADE, null= True )
def __str__(self):
return self.body
......@@ -13,12 +13,13 @@ def forum(request):
post.pub_datetime.strftime("%m/%d/%Y, %I:%M %p"),
post.body
)
for reply in replies:
if reply.forum_post == post:
response += "Reply by {} posted {}:<br>{}<br>".format(
reply.author,
reply.pub_datetime.strftime("%m/%d/%Y, %I:%M %p"),
reply.body
)
response += "<br>"
return HttpResponse(response)
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment