Commit adcb3764 authored by Stephanie Tullao's avatar Stephanie Tullao

Updated Forum views to display all Posts and Replies

parent 3081af56
from django.shortcuts import render from django.shortcuts import render
from django.http import HttpResponse from django.http import HttpResponse
from .models import Post, Reply
def index(request): def index(request):
return HttpResponse("Welcome to Widget's Forum!") heading = 'FORUM POSTS:<br>'
posts = Post.objects.all()
body = ''
for post in posts:
post_replies = Reply.objects.filter(original_post=post)
body += '{} by {} {} dated {}:<br>{}<br>'.format(
post.post_title, post.author.first_name, post.author.last_name,
post.pub_date, post.post_body
)
for post_reply in post_replies:
body += 'Reply by {} {} dated {}:<br>{}<br>'.format(
post_reply.author.first_name, post_reply.author.last_name,
post_reply.pub_date, post_reply.reply_body
)
body += '<br>'
return HttpResponse(heading + body)
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