Commit f194822d authored by Jan Enzo Salvador's avatar Jan Enzo Salvador

Edited the CBV of detail of forumpost so that I can access the all the Reply objects.

parent 5c511837
from django.shortcuts import render, redirect from django.shortcuts import render, redirect
from django.views.generic import DetailView, CreateView, UpdateView from django.views.generic import DetailView, CreateView, UpdateView, ListView
from .models import ForumPost, Reply from .models import ForumPost, Reply
# dashboard view from .models # dashboard view from .models
def forum_view(request): def forum_view(request):
forumposts = ForumPost.objects.all() forumposts = ForumPost.objects.all()
return render(request, 'forum/forum.html', {'forumposts': forumposts}) replies = Reply.objects.all()
return render(request, 'forum.html', {'forumposts': forumposts, 'replies': replies})
class ForumPostDetailView(DetailView): class ForumPostDetailView(DetailView):
def get_context_data(self, **kwargs):
context = super().get_context_data(**kwargs)
context['replies'] = Reply.objects.all()
return context
model = ForumPost model = ForumPost
template_name = "forum/forumpost-details.html" template_name = "forumpost-details.html"
class ForumPostCreateView(CreateView): class ForumPostCreateView(CreateView):
model = ForumPost model = ForumPost
template_name = "forum/forumpost-add.html" template_name = "forumpost-add.html"
fields = "__all__" fields = "__all__"
class ForumPostUpdateView(UpdateView): class ForumPostUpdateView(UpdateView):
model = ForumPost model = ForumPost
template_name = "forum/forumpost-edit.html" template_name = "forumpost-edit.html"
fields = "__all__" fields = "__all__"
......
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