Commit 44d17cc2 authored by Titia de Castro's avatar Titia de Castro

transformed announcements index view from FBV to CBV

parent 653d6958
from django.urls import path
from .views import index, AnnouncementDetailView, announcement_form
from .views import AnnouncementsView, AnnouncementDetailView, announcement_form
urlpatterns = [
path('', index, name='index'),
path('', AnnouncementsView.as_view(), name='index'),
path('<int:pk>/details/', AnnouncementDetailView.as_view(), name='announcement-details'),
path('add/', announcement_form, name='new-announcement'),
]
......
from django.shortcuts import render, redirect
from django.http import HttpResponse
from django.views import View
from django.views.generic.detail import DetailView
from .models import Announcement
......@@ -7,7 +8,8 @@ from .forms import AnnouncementForm
# Create your views here.
def index(request):
class AnnouncementsView(View):
def get(self, request):
return render(request, 'index.html', {'announcements': Announcement.objects.order_by('-pub_date')})
class AnnouncementDetailView(DetailView):
......
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