Django – How to specify which field a validation fails on?

OK, I figured it out from this answer.

You have to do something like this:

class Dog(models.Model):
    bark_volume = models.DecimalField(...
    unladen_speed = models.DecimalField(...

    def clean_fields(self):
        if self.bark_volume < 5:
            raise ValidationError({'bark_volume': ["Must be louder!",]})

Leave a Comment

tech