re: Django inline formsets with Class-based views and crispy forms VIEW POST

TOP OF THREAD FULL DISCUSSION
re: So I've figured out how to add validation for the CollectionTitle, but im doing it through views.py. Wondering if anybody knows how to add the vali...
 

Great code! have been looking all day :/
This works for me

    def form_valid(self, form):
        context = self.get_context_data()
        subunits = context['subunits']
        with transaction.atomic():
            if subunits.is_valid():
                self.object = form.save()
                subunits.instance = self.object
                subunits.save()
                return super(UnitCreateView, self).form_valid(form)
            else:
                return self.render_to_response(self.get_context_data(form=form))
code of conduct - report abuse