django - Raise field error in models clean method -


how raise validationexception in models clean method?

def clean(self):     django.core.exceptions import validationerror     raise validationerror({'title': 'not ok'}) 

the above not add error title field (when using form), non field errors.

i know how inside form (self._errors['title'] = self.error_class([msg])), self._errors not exist inside models clean method.

you don't, model's clean method meant raising non field errors, can raise field error creating clean_title method.

def clean(self):     """     hook doing model-wide validation after clean() has been     called on every field self.clean_fields. validationerror raised     method not associated particular field;     have special-case association field defined non_field_errors.     """ 

Comments

Popular posts from this blog

SPSS keyboard combination alters encoding -

Add new record to the table by click on the button in Microsoft Access -

javascript - jQuery .height() return 0 when visible but non-0 when hidden -