Add required_if field to model fields
|Reported by:||hejsan||Owned by:||nobody|
|Component:||Database layer (models, ORM)||Version:|
|Has patch:||no||Needs documentation:||no|
|Needs tests:||no||Patch needs improvement:||no|
I propose to add a required_if field to model fields (and form fields also i guess?)
It should take a callable that returns either True or False.
Another option would be to allow the required field to accept a callable.
Very often we have a "Published" field on our models (or "Published date" or "Published status" etc..) It would be very nice to be able to allow people to save instances without all the required fields being filled in IF the article or whathaveyou is not published yet.
Currently to do this you have to make all the fields not required and then override the save method. This would be a very handy feature for a very common problem.
Caveat: This means that the field should not be declared as "NOT NULL" in the database, but I don't really see that as a problem if validation is performed by django anyway.