Updated views for forum page

parent 96ad237d
from django.http import HttpResponse from django.http import HttpResponse
from forum.models import Post
from forum.models import Reply
# Create your views here. # Create your views here.
def index(request): def index(request):
return HttpResponse("Welcome to Widget’s Forum!") post_objects = Post.objects.all()
\ No newline at end of file reply_objects = Reply.objects.all()
response = "FORUM POSTS:"
for post in post_objects:
response = (response + f"<br> {post.post_title} by "
+ f"{post.author.first_name} {post.author.last_name} "
+ f"dated {post.pub_date.date()}:<br> {post.post_body} <br>")
for reply in reply_objects:
if(reply.post.post_title==post.post_title):
response = (response + "Reply by "
+ f"{reply.author.first_name} {reply.author.last_name} "
+ f"dated {reply.pub_date.date()}:<br> {reply.reply_body} <br>")
return HttpResponse(response)
\ 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