2👍
✅
You should do this in the proper place, instead of in save
To assign exceptions to a specific field, instantiate the
ValidationError with a dictionary, where the keys are the field names.
We could update the previous example to assign the error to the
pub_date field:
class Article(models.Model):
...
def clean(self):
# Don't allow draft entries to have a pub_date.
if self.status == 'draft' and self.pub_date is not None:
raise ValidationError({'pub_date': 'Draft entries may not have a publication date.'})
...
Source:stackexchange.com