Commit 8f1976f6 authored by Stephanie Tullao's avatar Stephanie Tullao

Converted post_list_view to CBV and added post_create_view

parent b4a612b9
from django.shortcuts import render from django.shortcuts import render
from django.http import HttpResponse from django.views import View
from django.views.generic.list import ListView from django.views.generic.edit import CreateView
from django.views.generic.detail import DetailView
from .models import Post, Reply from .models import Post, Reply
class post_list_view(View):
def post_list_view(request): def get(self, request):
context = {} post_list = Post.objects.order_by('-pub_date').all()
context['post_list'] = Post.objects.order_by('-pub_date').all() return render(request, 'forum/forum_list.html', {
return render(request, 'forum/forum_list.html', context) "post_list" : post_list
})
def post_detail_view(request, post_id): def post_detail_view(request, post_id):
post = Post.objects.get(id=post_id) post = Post.objects.get(id=post_id)
...@@ -18,3 +17,9 @@ def post_detail_view(request, post_id): ...@@ -18,3 +17,9 @@ def post_detail_view(request, post_id):
'reply_list': reply_list 'reply_list': reply_list
} }
return render(request, 'forum/forum_details.html', context) return render(request, 'forum/forum_details.html', context)
class post_create_view(CreateView):
model = Post
fields = '__all__'
success_url = '/forum/'
\ 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