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)
Metadata
Release files for drf-fullclean 0.0.3
For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.
Source distribution (sdist)
| File | Size | Uploaded | |
|---|---|---|---|
| drf_fullclean-0.0.3.tar.gz | 6.1 kB | Details |
Built distribution (wheel)
| File | Interpreter | ABI | Platform | Reset |
|---|---|---|---|---|
| drf_fullclean-0.0.3-py3-none-any.whl | Python 3 | none | any | Details |
Total release size: 13.5 kB
Release files / drf_fullclean-0.0.3.tar.gz
| Download URL | drf_fullclean-0.0.3.tar.gz |
|---|---|
| Size | 6.1 kB |
| Tags | Source |
|
SHA-256 checksum How to use checksums |
73708d3e4e195cbfd00a9590f0539518c58ef40b0d08243fd3c0e7dd2386d68d
|
|
BLAKE2b-256 checksum How to use checksums |
f3cad7f5efca5e8736398d5a33f94deabb2be9847915d9d4b2090d791226c5a8
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
twine/5.1.1 CPython/3.9.6
|
Release files / drf_fullclean-0.0.3-py3-none-any.whl
| Download URL | drf_fullclean-0.0.3-py3-none-any.whl |
|---|---|
| Size | 7.4 kB |
| Tags | Python 3 |
|
SHA-256 checksum How to use checksums |
ab32799240e641bcaf9d94935bb4f1f25c2a5a7111a204eab423747b32aca543
|
|
BLAKE2b-256 checksum How to use checksums |
316d9a88ebe6adea9776b36250e57b1c41eb145ff4820e8cb8dbc4a55a0cf5e6
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
twine/5.1.1 CPython/3.9.6
|