Call django model full_clean() when validate ModelSerializer
Project description
drf-fullclean
Call django Model.full_clean(exclude=None, validate_unique=True) when invoke serializer.is_valid() of ModelSerializer
Django Rest Framework 3 Design
Differences between ModelSerializer validation and ModelForm.
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.
Discussions
https://github.com/encode/django-rest-framework/discussions/7850
Warning!
- One ModelSerializer -> Use this library.
- Multiple ModelSerializer -> PLEASE READ ME
Installation
pip install drf-fullclean
Configuration
Add the following code into settings.py
DRF_FULL_CLEAN = {
"DEBUG" : False #set True if you want to see debug print
}
Usage
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.
API
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)
Project details
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
Built Distribution
File details
Details for the file drf_fullclean-0.0.3.tar.gz
.
File metadata
- Download URL: drf_fullclean-0.0.3.tar.gz
- Upload date:
- Size: 6.1 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/5.1.1 CPython/3.9.6
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | 73708d3e4e195cbfd00a9590f0539518c58ef40b0d08243fd3c0e7dd2386d68d |
|
MD5 | 9bf920bec63f7a3dff44d3622da85b25 |
|
BLAKE2b-256 | f3cad7f5efca5e8736398d5a33f94deabb2be9847915d9d4b2090d791226c5a8 |
File details
Details for the file drf_fullclean-0.0.3-py3-none-any.whl
.
File metadata
- Download URL: drf_fullclean-0.0.3-py3-none-any.whl
- Upload date:
- Size: 7.4 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/5.1.1 CPython/3.9.6
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | ab32799240e641bcaf9d94935bb4f1f25c2a5a7111a204eab423747b32aca543 |
|
MD5 | 304767aebb9c82eb7bfef3c8d729b69f |
|
BLAKE2b-256 | 316d9a88ebe6adea9776b36250e57b1c41eb145ff4820e8cb8dbc4a55a0cf5e6 |