Skip to main content

drf-fullclean

PyPI - Version PyPI - Downloads

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

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)

Source distribution for drf-fullclean 0.0.3
File Size Uploaded
drf_fullclean-0.0.3.tar.gz 6.1 kB Details

Built distribution (wheel)

Table of built distributions (wheels) for drf-fullclean 0.0.3
File Interpreter ABI Platform
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

Release history Release notifications | RSS feed

This release

0.0.3 This release

2 release files

0.0.2

2 release files

0.0.1

2 release files

Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page