1

Does anyone know how to validate form when CreateWithInlinesView from the Django Extra Views is used?

Surprisingly enough def clean(self) and def clean_name_of_the_field methods don't work there. I have checked it on function based view , so that they really don't work in CreateWithInlinesView. I could still use validators and def clean() in model, but I would prefer to do it in forms...

If you had any experience in CreateWithInlinesView validation -please let me know.

Thank you!

Daniel Holmes
  • 1,952
  • 2
  • 17
  • 28
Aleksei Khatkevich
  • 1,923
  • 2
  • 10
  • 27

1 Answers1

1

I know that this is late but I also faced the same problem. I have just added a few things to help with understanding. This can be done in the views. I found a solution here

class ModelCreate(CreateWithInlinesView):
    model = models.Model
    inlines = [ModelInline]
    form_class = forms.ModelForm
    success_url = reverse_lazy("app:related_name")

    def forms_valid(self, form, inlines):
        self.object = form.save()
        """Write your extra code in here"""
        return HttpResponseRedirect(self.get_success_url())
Codebender
  • 195
  • 1
  • 10