Commit 759a399a authored by Tanya's avatar Tanya

edited the url views for app forum

parent 754ddf32
from django.shortcuts import render from django.shortcuts import render
from django.http import HttpResponse from django.http import HttpResponse
from .models import ForumPost, Reply
from dashboard.models import WidgetUser
def index(request): def index(request):
return HttpResponse('Hello! This is the Forum.')
\ No newline at end of file return_string = '<body>'
for post in ForumPost.objects.all():
post_heading = '{} by {} {} posted {}:<br>'.format(
post.title,
post.author.first_name,
post.author.last_name,
post.pub_datetime.strftime("%m/%d/%Y, %I:%M %p")
)
post_body = '{}<br>'.format(post.body)
post_replies = ''
for reply in Reply.objects.filter(forum_post=post):
post_replies+= 'Reply by {} {} posted {}:<br>'.format(
reply.author.first_name,
reply.author.last_name,
reply.pub_datetime.strftime("%m/%d/%Y, %I:%M %p")
)
post_replies += '{}<br>'.format(reply.body)
return_string += post_heading + post_body + post_replies + '<br>'
html_string ='<html>{}</html>'.format(return_string)
return HttpResponse('Widget’s Forum<br><br>Forum Posts:<br>' + html_string)
\ 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