Added Views

parent 5ab80d8f
from django.shortcuts import render from django.shortcuts import render
from django.http import HttpResponse from django.urls import reverse
from django.views.generic import DetailView, CreateView, UpdateView
from .models import ForumPost, Reply from .models import ForumPost, Reply
from .forms import ForumPostForm
# Create your views here. # Create your views here.
def index(request): def ForumViews(request):
return_string = '<body> <ul>' forum = ForumPost.objects.all()
context = {'forum':forum}
return render(request, 'forum.html', context)
for post in ForumPost.objects.all(): class ForumPostDetails(DetailView):
return_string += '<li>{} by {} posted {}:<br>{}</li>'.format( template_name= "forumpost-details.html"
post.title, post.author, post.pub_datetime.strftime('%m/%d/%Y %H:%M %p'), post.body model = ForumPost
)
for replypost in Reply.objects.all():
if replypost.forum_post == post:
return_string += '<li>Reply by {} posted {}:<br>{}</li>'.format(
replypost.author, replypost.pub_datetime.strftime('%m/%d/%Y %I:%M %p'), replypost.body
)
return_string += '<br>'
return_string += '</ul></body>' class ForumPostNew(CreateView):
form_class = ForumPostForm
template_name = "forumpost-add.html"
html_string = '<html>{}</html>'.format(return_string) def get_success(self):
return reverse('forum:forumpostnew', kwargs = {'pk': self.object.id},
current_app=self.request.resolver_match.namespace)
return HttpResponse(html_string) class ForumPostEdit(UpdateView):
\ No newline at end of file form_class = ForumPostForm
template_name = "forumpost-edit.html"
queryset = ForumPost.objects.all()
def get_success_url(self):
return reverse('forum:forumpostdetails', kwargs = {'pk': self.object.pk},
current_app=self.request.resolver_match.namespace)
\ 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