Commit 261d274c authored by Eugene Ezekiel P. Tan's avatar Eugene Ezekiel P. Tan

added CBV for Forum

parent adfc2aac
from django.urls import path from django.urls import path
from .views import MainForumPage
from . import views from . import views
app_name = "Forum" app_name = "Forum"
urlpatterns = [ urlpatterns = [
#forum home page #forum home page
path('', views.index, name='index'), path('', MainForumPage.as_view(), name='index'),
#forum posts #forum posts
path("<int:post_id>/details/", views.posts, name='post'), path("<int:post_id>/details/", views.posts, name='post'),
#making new forum posts #making new forum posts
path("posts/add/", views.newPost,name= 'addPost') path("posts/add/", views.newPost,name='addPost')
] ]
from django.http import HttpResponse from django.http import HttpResponse
from django.views import View
import Forum import Forum
from .forms import PostForm from .forms import PostForm
from . models import Post, Reply from . models import Post, Reply
from homepage.models import WidgetUser from homepage.models import WidgetUser
from django.shortcuts import render, redirect from django.shortcuts import render, redirect
def index(request): class MainForumPage(View):
Posts = Post.objects.all() def get(self, request):
Replies = Reply.objects.all() Posts = Post.objects.all()
post_list = Post.objects.order_by("-pub_date") Replies = Reply.objects.all()
context ={ post_list = Post.objects.order_by("-pub_date")
'Post':Posts, context ={
'Reply':Replies, 'Post':Posts,
'post_list':post_list 'Reply':Replies,
} 'post_list':post_list
return render(request, "Forum/view.html", context) }
return render(request, "Forum/view.html", context)
def posts(request, post_id): def posts(request, post_id):
reply_list = Reply.objects.order_by("-pub_date") reply_list = Reply.objects.order_by("-pub_date")
......
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