Adding content to course modules

Now, we need a way to add content to course modules. We have four different types of content: text, video, image, and file. We can consider creating four different views to create content, one for each model. Yet we are going to take a more generic approach and create a view that handles creating or updating objects of any content model.

Edit the views.py file of the courses application and add the following code to it:

from django.forms.models import modelform_factoryfrom django.apps import appsfrom .models import Module, Contentclass ContentCreateUpdateView(TemplateResponseMixin, View):    module = None    model = None    obj = None    template_name = 'courses/manage/content/form.html' def get_model(self, model_name): ...

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.