Commit 6e60c621 authored by karin-kurusu's avatar karin-kurusu

Updated views.py pageview to reflect specifications, implemented DetailView, CreateView, UpdateView

parent 52f439b3
from django.shortcuts import render
from .models import ForumPost, Reply
from django.http import HttpResponse
from django.views.generic.detail import DetailView
from django.views.generic.edit import CreateView, UpdateView
def pageview(request):
forumposts = ForumPost.objects.all()
forumposts = ForumPost.objects.order_by("-pub_datetime")
replys = Reply.objects.all()
string_builder = "Widget's Forum <br> <br> Forum Posts: <br> "
return render(request, 'forum/forum.html', {'forumposts': forumposts, 'replys': replys})
for forumpost in forumposts:
class ForumpostDetailView(DetailView):
def get(self, request, pk):
forumpost = ForumPost.objects.get(pk=pk)
reply = Reply.objects.filter(forum_post=forumpost)
return render(request, 'forum/forumpost-details.html', {'forumpost': forumpost, 'reply': reply})
string_builder = "{} <br> {} by {} posted {} <br> {}".format(
string_builder,
forumpost.title,
forumpost.author,
forumpost.pub_datetime.strftime("%m/%d/%Y, %I:%M %p:"),
forumpost.body
)
for reply in replys:
if reply.forum_post == forumpost:
string_builder = "{} <br> Reply by {} posted {} <br> {}".format(
string_builder,
reply.author,
reply.pub_datetime.strftime("%m/%d/%Y, %I:%M %p:"),
reply.body
)
string_builder += "<br>"
return HttpResponse(string_builder)
class ForumpostCreateView(CreateView):
model = ForumPost
fields = '__all__'
template_name = 'forum/forumpost-add.html'
class ForumpostUpdateView(UpdateView):
model = ForumPost
fields = '__all__'
template_name = 'forum/forumpost-edit.html'
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