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): ...