Commit 717e2b08 authored by Andre Dalwin C. Tan's avatar Andre Dalwin C. Tan 💬

Updated Views.py

parent 030df003
from django.shortcuts import render
from django.http import HttpResponse
from .models import ForumPost, Reply
from .models import ForumPost
# Create your views here.
......@@ -9,10 +9,10 @@ def forum(request):
# fetch forum posts and replies
forum = ForumPost.objects.all()
replies = Reply.objects.all()
forum_view = "Widget's Forum <br> <br> Forum Posts:<br>"
for post in forum:
post_replies = post.reply_set.all()
forum_view += '''
{} by {} posted {}: <br>
{} <br>
......@@ -23,15 +23,14 @@ def forum(request):
post.body,
)
# Check if reply is for that specific forum_post
for reply in replies:
if reply.forum == post:
forum_view += '''
Reply by {} posted {}: <br>
{} <br>
'''.format(
reply.author,
reply.pub_datetime.strftime("%m/%d/%Y, %I:%M %p"),
reply.body
)
for reply in post_replies:
forum_view += '''
Reply by {} posted {}: <br>
{} <br>
'''.format(
reply.author,
reply.pub_datetime.strftime("%m/%d/%Y, %I:%M %p"),
reply.body
)
forum_view += "<br>"
return HttpResponse(forum_view)
\ No newline at end of file
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