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