Commit 4776007d authored by Jan Enzo Salvador's avatar Jan Enzo Salvador

FBV implementation for the forum page

parent 9a8e6e56
from django.http import HttpResponse
from .models import ForumPost, Reply
from django.shortcuts import render, redirect
from django.views.generic import DetailView, CreateView, UpdateView
from .models import ForumPost
from .forms import AddForumPostForm
# dashboard view from .models
def forum_view(request):
users = ForumPost.objects.all()
return render(request, 'forum/forum.html', {'users': users})
# forum view from .models
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_post.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>"
)
forum_output = forum_output + "<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