Commit b08e7b70 authored by Jan Enzo Salvador's avatar Jan Enzo Salvador

Created the views of the forum showing the forum posts and their corresponding replies

parent f989bad9
from django.shortcuts import render
from django.http import HttpResponse
from .models import ForumPost, Reply
# Create your views here.
def forumIndex(request):
# fetch forum posts and replies
forum = ForumPost.objects.all()
replies = Reply.objects.all()
forum_output = "Widget's Forum <br><br> Forum Posts:<br>"
for post in forum:
forum_output = (forum_output + post.title + " by " + post.author.first_name + + post.author.last_name +
" posted " + post.pub_datetime.strftime('%m/%d/%Y, %I:%M %p') + ":<br>" +
post.body + "<br>"
)
for reply in replies:
if reply.forum_posts.title == post.title:
forum_output = (forum_output + "Reply by " + reply.author.first_name + " " + reply.author.last_name
+ " posted " + reply.pub_datetime.strftime('%m/%d/%Y, %I:%M %p') + ":<br>" +
reply.body + "<br><br>"
)
return HttpResponse(forum_output)
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