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)

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.3.tar.gz (6.1 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

drf_fullclean-0.0.3-py3-none-any.whl (7.4 kB view details)

Uploaded Python 3

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

Hashes for drf_fullclean-0.0.3.tar.gz
Algorithm Hash digest
SHA256 73708d3e4e195cbfd00a9590f0539518c58ef40b0d08243fd3c0e7dd2386d68d
MD5 9bf920bec63f7a3dff44d3622da85b25
BLAKE2b-256 f3cad7f5efca5e8736398d5a33f94deabb2be9847915d9d4b2090d791226c5a8

See more details on using hashes here.

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

Hashes for drf_fullclean-0.0.3-py3-none-any.whl
Algorithm Hash digest
SHA256 ab32799240e641bcaf9d94935bb4f1f25c2a5a7111a204eab423747b32aca543
MD5 304767aebb9c82eb7bfef3c8d729b69f
BLAKE2b-256 316d9a88ebe6adea9776b36250e57b1c41eb145ff4820e8cb8dbc4a55a0cf5e6

See more details on using hashes here.

Release history Release notifications | RSS feed

This release

0.0.3 This release

2 files

0.0.2

2 files

0.0.1

2 files

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page