Call django model full_clean() when validate ModelSerializer
Project description
drf-fullclean
Call django model full_clean() when validate ModelSerializer
Installation
pip install drf-fullclean
Usage
s = ModelSerializerClass(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.
serializer_obj.is_valid(self, raise_exception=False, include=None, validate_unique=True, *args, **kwargs)
- raise_exception=False
- validate_unique=True
- include=None
- This parameter accept a type of
dict
:{'model_field_name' : instance_obj}
and performexclude=None
method to Model.full_clean() api. - If you want to perform
Model.full_clean()
you must have the model instance with ALL FIELD POPULATED. - Into some scenario, for example, when you try to save nested instance, some ForeignKey are None. So before validate you must create an instance of this ForeignKey without save into db and pass it into
include=None
parameter. This action exclude it, byModel.full_clean()
validation, but not fromModel.clean()
method. A ForeignKey with pk=None can't be validated byModel.clean_field()
method.
- This parameter accept a type of
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
drf_fullclean-0.0.1.tar.gz
(4.5 kB
view details)
Built Distribution
File details
Details for the file drf_fullclean-0.0.1.tar.gz
.
File metadata
- Download URL: drf_fullclean-0.0.1.tar.gz
- Upload date:
- Size: 4.5 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/5.1.1 CPython/3.9.6
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | 7b586bd8229dc72cf58799ac064df0a3bb5f3f2328348cc9a056434c378b68f9 |
|
MD5 | b0603b9bf699f44bcd4a4ef2c46fa9d2 |
|
BLAKE2b-256 | 72392e43a0c186e1577498e998149f74588d206f8f1515d05b72ca7df250c298 |
File details
Details for the file drf_fullclean-0.0.1-py3-none-any.whl
.
File metadata
- Download URL: drf_fullclean-0.0.1-py3-none-any.whl
- Upload date:
- Size: 5.3 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 | 027b314dc69bb9fe6d44a6790ed8d422cc01cefccce0c5ab2a751bb11289108d |
|
MD5 | d56c40ba587590142aac6f44608339d3 |
|
BLAKE2b-256 | 547897e5af8f9e82259cb795feab934493d4d584825e8437cd1c01df9276dfbd |