Skip to main content

Django REST framework keywords names for extra_keyword meta attribute of serializers stored as constants

Project description

drfkwargs

Django REST framework keywords names for extra_keyword meta attribute of serializers stored as constants


Installing

[!NOTE] It's recommended to activate Virtual Environment before installing drfkwargs

To clone and install required packages use the following command:

# linux/macOS
$ python3 -m pip install drfkwargs

# windows
$ py -3 -m pip install drfkwargs

Quick example

import django.contrib.auth.models

import rest_framework.serializers

import drfkwargs


class UserSerializer(rest_framework.serializers.ModelSerializer):

    class Meta:
        model = django.contrib.auth.models.User
        fields = rest_framework.serializers.ALL_FIELDS
        extra_kwargs = {
            model.password.field.name: {drfkwargs.WRITE_ONLY: True},
            model.user_permissions.field.name: {drfkwargs.WRITE_ONLY: True},
            model.groups.field.name: {drfkwargs.WRITE_ONLY: True},
        }

Class-based kwargs

For more readability you can use class-based keyword argument sets, which are classes providing the set of the kwargs names available for a serializer. Going with this, it's possible to replace drfkwargs.INPUT_FORMATS with drfkwargs.DateFieldKwargs.INPUT_FORMATS. These two are the equivalents, but the second one provides more information about what is this kwarg

[!NOTE] Every serializer provided by DRF has its own class-based kwarg set

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

drfkwargs-1.0.0.tar.gz (4.0 kB view details)

Uploaded Source

Built Distribution

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

drfkwargs-1.0.0-py3-none-any.whl (5.2 kB view details)

Uploaded Python 3

File details

Details for the file drfkwargs-1.0.0.tar.gz.

File metadata

  • Download URL: drfkwargs-1.0.0.tar.gz
  • Upload date:
  • Size: 4.0 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.1.0 CPython/3.11.9

File hashes

Hashes for drfkwargs-1.0.0.tar.gz
Algorithm Hash digest
SHA256 8fb420b82be5511dac4ae44ad124a892393a695244a44b256911e09d658ed0ad
MD5 0177177a8adc5f02a1a3693e29862a4d
BLAKE2b-256 460c0e56c9e7fce67a1909dd6df709ab05ef33fcc10c972649b7fd6421275825

See more details on using hashes here.

File details

Details for the file drfkwargs-1.0.0-py3-none-any.whl.

File metadata

  • Download URL: drfkwargs-1.0.0-py3-none-any.whl
  • Upload date:
  • Size: 5.2 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.1.0 CPython/3.11.9

File hashes

Hashes for drfkwargs-1.0.0-py3-none-any.whl
Algorithm Hash digest
SHA256 d493049ca8179dd4dfd32e6d4c29cfc3ac8e32a18a3dfa5700e2686c5444a0f7
MD5 f6b8fb3a51b62d4ba52d8e0089ce953b
BLAKE2b-256 acd8bf89843fbb9f2dc248228c2a2e584dd0f9e4f709fb5076dbeece24a88f8f

See more details on using hashes here.

Supported by

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