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