We have built views to create, edit, and delete course modules and contents. Now, we need a view to display all modules for a course and list contents for a specific module.
Edit the views.py file of the courses application and add the following code to it:
class ModuleContentListView(TemplateResponseMixin, View): template_name = 'courses/manage/module/content_list.html' def get(self, request, module_id): module = get_object_or_404(Module, id=module_id, course__owner=request.user) return self.render_to_response({'module': module})
This is ModuleContentListView. This view gets the Module object with the given ID that belongs to the current user and renders a template with the given module.
Edit the urls.py file ...