Name | drf-fullclean JSON |
Version |
0.0.3
JSON |
| download |
home_page | https://github.com/giuseppenovielli/drf-fullclean |
Summary | Call django model full_clean() when validate ModelSerializer |
upload_time | 2024-09-09 16:00:35 |
maintainer | None |
docs_url | None |
author | Giuseppe Novielli |
requires_python | >=3.7 |
license | MIT License Copyright (c) 2024 Giuseppe Novielli Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions: The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software. THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. |
keywords |
django-rest-framework
model-serializer
validate
full_clean
|
VCS |
|
bugtrack_url |
|
requirements |
No requirements were recorded.
|
Travis-CI |
No Travis.
|
coveralls test coverage |
No coveralls.
|
# drf-fullclean
![PyPI - Version](https://img.shields.io/pypi/v/drf-fullclean)
![PyPI - Downloads](https://img.shields.io/pypi/dm/drf-fullclean)
**Call django Model.full_clean(exclude=None, validate_unique=True) when invoke serializer.is_valid() of ModelSerializer**
### Django Rest Framework 3 Design
https://www.django-rest-framework.org/community/3.0-announcement/#differences-between-modelserializer-validation-and-modelform
### 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!
1. One ModelSerializer -> Use this library.
2. Multiple ModelSerializer -> [PLEASE READ ME](https://github.com/giuseppenovielli/drf-fullclean/discussions/4)
## 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)
```
+ [raise_exception=False](https://www.django-rest-framework.org/api-guide/serializers/#raising-an-exception-on-invalid-data)
+ [exclude=None](https://docs.djangoproject.com/en/3.2/ref/models/instances/#django.db.models.Model.full_clean)
+ [validate_unique=True](https://docs.djangoproject.com/en/3.2/ref/models/instances/#django.db.models.Model.full_clean)
+ [extra_include=None](https://github.com/giuseppenovielli/drf-fullclean/discussions/4)
Raw data
{
"_id": null,
"home_page": "https://github.com/giuseppenovielli/drf-fullclean",
"name": "drf-fullclean",
"maintainer": null,
"docs_url": null,
"requires_python": ">=3.7",
"maintainer_email": null,
"keywords": "django-rest-framework, model-serializer, validate, full_clean",
"author": "Giuseppe Novielli",
"author_email": "novielligiuseppe@gmail.com",
"download_url": "https://files.pythonhosted.org/packages/f3/ca/d7f5efca5e8736398d5a33f94deabb2be9847915d9d4b2090d791226c5a8/drf_fullclean-0.0.3.tar.gz",
"platform": null,
"description": "# drf-fullclean\n![PyPI - Version](https://img.shields.io/pypi/v/drf-fullclean)\n![PyPI - Downloads](https://img.shields.io/pypi/dm/drf-fullclean)\n\n**Call django Model.full_clean(exclude=None, validate_unique=True) when invoke serializer.is_valid() of ModelSerializer**\n\n### Django Rest Framework 3 Design\nhttps://www.django-rest-framework.org/community/3.0-announcement/#differences-between-modelserializer-validation-and-modelform\n### Differences between ModelSerializer validation and ModelForm.\n> 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.\n\n### Discussions\nhttps://github.com/encode/django-rest-framework/discussions/7850\n\n## Warning!\n1. One ModelSerializer -> Use this library.\n2. Multiple ModelSerializer -> [PLEASE READ ME](https://github.com/giuseppenovielli/drf-fullclean/discussions/4)\n\n## Installation\n```\npip install drf-fullclean\n```\n\n## Configuration\nAdd the following code into settings.py\n```\nDRF_FULL_CLEAN = {\n \"DEBUG\" : False #set True if you want to see debug print\n}\n```\n\n## Usage\n```\nfrom drf_fullclean.serializers import FullCleanModelSerializer\n\nclass MyModelSerializerClass(FullCleanModelSerializer):\n class Meta:\n model = MyModel\n fields = '__all__\n```\n\n```\ns = MyModelSerializerClass(data=request.POST)\ns.is_valid(raise_exception=True)\ns.save()\n```\nWhen you call `s.is_valid(raise_exception=True)` this method invoke also Model.full_clean() method.\n\n**The validation FAIL IF Model.full_clean() FAIL.**\n\n## API\n`is_valid()` is extended with Model.full_clean() api.\n\n```\nis_valid(self, raise_exception=False, exclude=None, validate_unique=True, extra_include=None, *args, **kwargs)\n```\n + [raise_exception=False](https://www.django-rest-framework.org/api-guide/serializers/#raising-an-exception-on-invalid-data)\n + [exclude=None](https://docs.djangoproject.com/en/3.2/ref/models/instances/#django.db.models.Model.full_clean)\n + [validate_unique=True](https://docs.djangoproject.com/en/3.2/ref/models/instances/#django.db.models.Model.full_clean)\n + [extra_include=None](https://github.com/giuseppenovielli/drf-fullclean/discussions/4)\n \n\n\n",
"bugtrack_url": null,
"license": "MIT License Copyright (c) 2024 Giuseppe Novielli Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the \"Software\"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions: The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software. THE SOFTWARE IS PROVIDED \"AS IS\", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. ",
"summary": "Call django model full_clean() when validate ModelSerializer",
"version": "0.0.3",
"project_urls": {
"Documentation": "https://github.com/giuseppenovielli/drf-fullclean?tab=readme-ov-file#drf-fullclean",
"Funding": "https://buymeacoffee.com/giuseppedev",
"Homepage": "https://github.com/giuseppenovielli/drf-fullclean",
"Source": "https://github.com/giuseppenovielli/drf-fullclean",
"Tracker": "https://github.com/giuseppenovielli/drf-fullclean/issues"
},
"split_keywords": [
"django-rest-framework",
" model-serializer",
" validate",
" full_clean"
],
"urls": [
{
"comment_text": "",
"digests": {
"blake2b_256": "316d9a88ebe6adea9776b36250e57b1c41eb145ff4820e8cb8dbc4a55a0cf5e6",
"md5": "304767aebb9c82eb7bfef3c8d729b69f",
"sha256": "ab32799240e641bcaf9d94935bb4f1f25c2a5a7111a204eab423747b32aca543"
},
"downloads": -1,
"filename": "drf_fullclean-0.0.3-py3-none-any.whl",
"has_sig": false,
"md5_digest": "304767aebb9c82eb7bfef3c8d729b69f",
"packagetype": "bdist_wheel",
"python_version": "py3",
"requires_python": ">=3.7",
"size": 7371,
"upload_time": "2024-09-09T16:00:34",
"upload_time_iso_8601": "2024-09-09T16:00:34.256913Z",
"url": "https://files.pythonhosted.org/packages/31/6d/9a88ebe6adea9776b36250e57b1c41eb145ff4820e8cb8dbc4a55a0cf5e6/drf_fullclean-0.0.3-py3-none-any.whl",
"yanked": false,
"yanked_reason": null
},
{
"comment_text": "",
"digests": {
"blake2b_256": "f3cad7f5efca5e8736398d5a33f94deabb2be9847915d9d4b2090d791226c5a8",
"md5": "9bf920bec63f7a3dff44d3622da85b25",
"sha256": "73708d3e4e195cbfd00a9590f0539518c58ef40b0d08243fd3c0e7dd2386d68d"
},
"downloads": -1,
"filename": "drf_fullclean-0.0.3.tar.gz",
"has_sig": false,
"md5_digest": "9bf920bec63f7a3dff44d3622da85b25",
"packagetype": "sdist",
"python_version": "source",
"requires_python": ">=3.7",
"size": 6122,
"upload_time": "2024-09-09T16:00:35",
"upload_time_iso_8601": "2024-09-09T16:00:35.616384Z",
"url": "https://files.pythonhosted.org/packages/f3/ca/d7f5efca5e8736398d5a33f94deabb2be9847915d9d4b2090d791226c5a8/drf_fullclean-0.0.3.tar.gz",
"yanked": false,
"yanked_reason": null
}
],
"upload_time": "2024-09-09 16:00:35",
"github": true,
"gitlab": false,
"bitbucket": false,
"codeberg": false,
"github_user": "giuseppenovielli",
"github_project": "drf-fullclean",
"travis_ci": false,
"coveralls": false,
"github_actions": false,
"lcname": "drf-fullclean"
}