1👍
✅
You can use Model.clean()
:
class M(models.Model):
A = models.BooleanField()
B = models.IntegerField(null=True, blank=True)
def clean(self):
if self.A and self.B is None:
raise ValidationError("B can not be None lwhile A is None")
You will raise ValidationError
in conditions that is not valid.
Source:stackexchange.com