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 django.shortcuts import render
from .models import ForumPost, Reply 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): def pageview(request):
forumposts = ForumPost.objects.all() forumposts = ForumPost.objects.order_by("-pub_datetime")
replys = Reply.objects.all() 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( class ForumpostCreateView(CreateView):
string_builder, model = ForumPost
forumpost.title, fields = '__all__'
forumpost.author, template_name = 'forum/forumpost-add.html'
forumpost.pub_datetime.strftime("%m/%d/%Y, %I:%M %p:"),
forumpost.body class ForumpostUpdateView(UpdateView):
) model = ForumPost
fields = '__all__'
for reply in replys: template_name = 'forum/forumpost-edit.html'
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)
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