Call django Model.full_clean(exclude=None, validate_unique=True) when invoke serializer.is_valid() of ModelSerializer
This change also means that we no longer use the .full_clean() method on model instances, but instead perform all validation explicitly on the serializer. This gives a cleaner separation, and ensures > that there's no automatic validation behavior on ModelSerializer classes that can't also be easily replicated on regular Serializer classes.
encode/django-rest-framework#7850
- One ModelSerializer -> Use this library.
- Multiple ModelSerializer -> PLEASE READ ME
pip install drf-fullclean
Add the following code into settings.py
DRF_FULL_CLEAN = {
"DEBUG" : False #set True if you want to see debug print
}
from drf_fullclean.serializers import FullCleanModelSerializer
class MyModelSerializerClass(FullCleanModelSerializer):
class Meta:
model = MyModel
fields = '__all__
s = MyModelSerializerClass(data=request.POST)
s.is_valid(raise_exception=True)
s.save()
When you call s.is_valid(raise_exception=True)
this method invoke also Model.full_clean() method.
The validation FAIL IF Model.full_clean() FAIL.
is_valid()
is extended with Model.full_clean() api.
is_valid(self, raise_exception=False, exclude=None, validate_unique=True, extra_include=None, *args, **kwargs)