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

后端 未结 6 1389
太阳男子
太阳男子 2021-01-31 01:43

I have this model I\'m showing in the admin page:

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


        
6条回答
  •  春和景丽
    2021-01-31 02:12

    abbreviated, from the django docs:

    def clean(self):
        data = self.cleaned_data
        subject = data.get("subject")
    
        if subject and "help" not in subject:
            msg = "Must put 'help' in subject."
            self.add_error('subject', msg)
    
        return data
    

提交回复
热议问题