[Django]-Blank, Null, and Required in Django Models and ModelForms

21👍

The contradictions don’t matter. I think this brings flexibility to the development of a Django application. For example, if you’re using a third party library that defines some models, and they set blank=True, but for other purposes you need that field is mandatory, then in your forms you can fix it without touching the third party library code.

This just add some flexibility to the framework IMHO, that brings no harm. You can use it for your own purposes. The contradictions are not significant.

Hope this helps!

3👍

It depends on the requirement. Sometime we decide later to make field mandatory on the form although on model it is still not required. But the form will ensure that field must be fill.

You can have null=True on the model and then later you can make that field mandatory on form. But you can not make a field optional in form when it is mandatory on model that will result in database error later on.

Leave a comment