django class-based views with inline model-form or formset
Key points is: generated FormSets within forms.py using inlineformset_factory: BookImageFormSet = inlineformset_factory(BookForm, BookImage, extra=2) BookPageFormSet = inlineformset_factory(BookForm, BookPage, extra=5) returned the FormSets within a CreateView class in views.py: def get_context_data(self, **kwargs): context = super(BookCreateView, self).get_context_data(**kwargs) if self.request.POST: context[‘bookimage_form’] = BookImageFormSet(self.request.POST) context[‘bookpage_form’] = BookPageFormSet(self.request.POST) else: context[‘bookimage_form’] = BookImageFormSet() context[‘bookpage_form’] = BookPageFormSet() return context Used form_valid to … Read more