Added Views

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