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)
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(): def get_success(self):
return_string += '<li>{} by {} posted {}:<br>{}</li>'.format( return reverse('forum:forumpostnew', kwargs = {'pk': self.object.id},
post.title, post.author, post.pub_datetime.strftime('%m/%d/%Y %H:%M %p'), post.body current_app=self.request.resolver_match.namespace)
)
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>'
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) def get_success_url(self):
\ No newline at end of file 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