Creating class-based views

We are going to build views to create, edit, and delete courses. We will use class-based views for this. Edit the views.py file of the courses application and add the following code to it:

from django.views.generic.list import ListViewfrom .models import Courseclass ManageCourseListView(ListView):    model = Course    template_name = 'courses/manage/course/list.html'    def get_queryset(self):        qs = super(ManageCourseListView, self).get_queryset()        return qs.filter(owner=self.request.user)

This is the ManageCourseListView view. It inherits from Django's generic ListView. We override the get_queryset() method of the view to retrieve only courses created by the current user. To prevent users from editing, updating, or deleting ...

Get Django 2 by Example now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.