Skip to main content

drf-model-serializer

Description

The scope of this module is to enhance DRF's ModelSerializer class, and provide object-level validation out of the box.

The idea is that the model defines its object-level validation in its clean method. The serializer class ModelSerializer provided by this module, overrides its validate method so that it invokes the model's clean method. Therefore whenever invoking the serializer's is_valid method, the validate method runs and provides the object-level validation.

This way, object-level validation is defined once in the model and is used automatically by the Django admin, the model when explicitly invoking full_clean and the serializer whenever invoking is_valid. This follows the convention for field-level validation. When defined correctly using model validators, the field-level validation is used out of the box by the Django admin, serializer and model.

Proving the validation idea

In this module, we also provide a Django project that will show you how the object level validations works together with Django admin, Serializer, and a model by implementing drf-model-serializer and model clean() method. A main focus of the test project lives on create/update actions over any drinks or main dishes recipe, which all any incoming data either from Admin or Serializer must be validated. See the Recipe model and the tests section to understand it in more detail.

Prerequisite

Ensure pip installed on your local machine. If you don't have it, you can follow the installation guide here.

How to run the tests

  1. Open terminal and go to the root directory of where the package live, for instance: $ cd Documents/py-projects/drf-model-serializer.
  2. Run $ ./scripts/requirement-install.sh from your command line.
  3. Run $ ./scripts/checker.sh.

How to run the test project

Currently only Recipe admin page that available to be explored, and to try it out you can follow these steps:

  1. Open terminal and go to the root directory of where the package live, for instance: $ cd Documents/py-projects/drf-model-serializer.
  2. Run $ ./scripts/requirement-install.sh from your command line (you can skip this if you already did it when running the tests).
  3. Run $ source venv/bin/activate && cd test_project && python manage.py migrate.
  4. Create admin user, run $ python manage.py createsuperuser --email admin@mail.com --username admin.
  5. Run $ python manage.py runserver 0.0.0.0:8000 and when server is ready, open the admin page and logged in with the previous Admin account.

Installation

$ pip install drf-model-serializer

or add this on your requirements.txt

drf-model-serializer==0.0.1

Get involved!

We are happy to receive bug reports, fixes, documentation enhancements, and other improvements.

Please report bugs via the github issue tracker.

Master git repository drf-model-serializer.

Release files for drf-model-serializer 0.0.2

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-model-serializer 0.0.2
File Size Uploaded
drf-model-serializer-0.0.2.tar.gz 3.2 kB Details

Built distribution (wheel)

Table of built distributions (wheels) for drf-model-serializer 0.0.2
File Interpreter ABI Platform
drf_model_serializer-0.0.2-py2-none-any.whl Python 2 none any Details

Total release size: 7.5 kB

Release files / drf-model-serializer-0.0.2.tar.gz

Download URL drf-model-serializer-0.0.2.tar.gz
Size 3.2 kB
Tags Source
SHA-256 checksum
How to use checksums
db18d21387ac6423aa470478db6ea0262685fe9dd6f217006c17e6f150e00f16
BLAKE2b-256 checksum
How to use checksums
fc0615f30262a2e6afc84e6043ca7bcbc60f511fbab28c1db92b22fcbb78d8d6
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/1.15.0 pkginfo/1.7.1 requests/2.26.0 setuptools/41.0.1 requests-toolbelt/0.9.1 tqdm/4.62.1 CPython/2.7.16

Release files / drf_model_serializer-0.0.2-py2-none-any.whl

Download URL drf_model_serializer-0.0.2-py2-none-any.whl
Size 4.4 kB
Tags Python 2
SHA-256 checksum
How to use checksums
0a1d8fba93dec1e26f5a8c3380bb572d41c5e387535341268b62ace9f487f5a6
BLAKE2b-256 checksum
How to use checksums
6fb48579c16adae885f8c9475436736e9f7534dbca97b8bf555598ae7a8ae3bb
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/1.15.0 pkginfo/1.7.1 requests/2.26.0 setuptools/41.0.1 requests-toolbelt/0.9.1 tqdm/4.62.1 CPython/2.7.16

Release history Release notifications | RSS feed

This release

0.0.2 This release

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