[Fixed]-Limit the value of a field according to another one

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.

👤Mp0int

Leave a comment