15π
From the documentation:
Model.full_clean(exclude=None, validate_unique=True):
This method calls
Model.clean_fields()
,Model.clean()
, and
Model.validate_unique()
(ifvalidate_unique
isTrue
), in that order
and raises aValidationError
that has amessage_dict
attribute
containing errors from all three stages.
Model.clean():
This method should be used to provide custom model validation, and to
modify attributes on your model if desired.
For more detailed explanation, have a look at the Validating objects section of the documentation.
2π
They are not against each other. Usually you call Model.full_clean(), which calls Model.clean() for custom validation.
For example:
from django.core.exceptions import ValidationError
from django.db import models
class Brand(models.Model):
title = models.CharField(max_length=512)
def clean(self):
if self.title.isdigit():
raise ValidationError("title must be meaningful not only digits")
def save(self, *args, **kwargs):
self.full_clean()
return super().save(*args, **kwargs)
- Django AuditTrail vs Reversion
- Making a text input field look disabled, but act readonly
- Django-templates: Why doesn't {% if "string"|length > 10 %} work at all?
- Forbidden (403) CSRF verification failed. Request aborted
- Python/Django polling of database has memory leak
1π
here are three steps involved in validating a model:
Validate the model fields β Model.clean_fields()
Validate the model as a whole β Model.clean()
Validate the field uniqueness β Model.validate_unique()
All three steps are performed when you call a modelβs full_clean()
method. for more information click here
- Django south: changing field type in data migration
- Django load local json file
- Django/Python: generate pdf with the proper language
- One project, Multiple customers with git?