B
B
Bjornie2017-08-17 23:09:55
Django
Bjornie, 2017-08-17 23:09:55

What needs to be done to reuse the data validation schema in a form?

My models have a lot of fields like DateField which I check if yes already passed. I just figured out how the field validation is done, and everything works as it should, but I did the validation of several fields of the same model (via clean ().
Having switched to other models, I realized that it would be wrong to write the same code every time. Tell me how it's done, what should I do to use the same schema in different models, different forms (ModelForm).

Answer the question

In order to leave comments, you need to log in

1 answer(s)
S
Sergey Gornostaev, 2017-08-17
@Bjornie

You can declare a class that receives a list of model fields in the clean method and checks them bypassing in a loop. And then to be inherited from it in the necessary forms.

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question