Skip to main content

Django REST EnumField

Build Status PyPI version Coveralls Status Black

EnumField that uses python enums for Django REST Framework

Installation

pip install django-rest-enumfield

Usage

Use it as if its a ChoiceField:

import enum
from rest_enumfield import EnumField

class Color(enum.Enum):
   RED = "red"
   GREEN = "green"
   BLUE = "blue"

class SomeSerializer(Serializer):

   color = EnumField(choices=Color)

Additionally you can override choice name and value generation by providing to_choice or to_repr arguments:

class SomeSerializer(Serializer):

   color = EnumField(choices=Color, to_choice=lambda x: (x.value, x.name), to_repr=lambda x: x.value)

This will cause the enum’s value instead of the name to be represented.

Thats it.

Release files for django-rest-enumfield 0.2.0

For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.

Source distribution (sdist)

Source distribution for django-rest-enumfield 0.2.0
File Size Uploaded
django-rest-enumfield-0.2.0.tar.gz 3.0 kB Details

Built distribution (wheel)

Table of built distributions (wheels) for django-rest-enumfield 0.2.0
File Interpreter ABI Platform
django_rest_enumfield-0.2.0-py2.py3-none-any.whl Python 3, Python 2 none any Details

Total release size: 7.0 kB

Release files / django-rest-enumfield-0.2.0.tar.gz

Download URL django-rest-enumfield-0.2.0.tar.gz
Size 3.0 kB
Tags Source
SHA-256 checksum
How to use checksums
0e3c1121e136dd7163c92737dcd67e0c6b78e78793b740b0811753343c7da8fe
BLAKE2b-256 checksum
How to use checksums
7dffab47c411c40253fd3fd66ebc04f2bd4e9034559f19d28aabef49f0f00689
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/1.13.0 pkginfo/1.5.0.1 requests/2.20.1 setuptools/41.0.1 requests-toolbelt/0.8.0 tqdm/4.28.1 CPython/3.7.4

Release files / django_rest_enumfield-0.2.0-py2.py3-none-any.whl

Download URL django_rest_enumfield-0.2.0-py2.py3-none-any.whl
Size 4.0 kB
Tags Python 2 Python 3
SHA-256 checksum
How to use checksums
80792326d5d8fad8a66729e9404a4078fe16f7eb8b2a910b37157d96df415611
BLAKE2b-256 checksum
How to use checksums
9c27e7b1b166a3e36983f73b49bfcb974e29f46807c3ebc1a2c5fc0ec0e8a8d9
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/1.13.0 pkginfo/1.5.0.1 requests/2.20.1 setuptools/41.0.1 requests-toolbelt/0.8.0 tqdm/4.28.1 CPython/3.7.4

Release history Release notifications | RSS feed

This release

0.2.0 This release

2 release files

0.1.2

2 release files

0.1.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