EnumField for Django REST Framework
Project description
Django REST EnumField
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.
Project details
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
Built Distribution
File details
Details for the file django-rest-enumfield-0.2.0.tar.gz
.
File metadata
- Download URL: django-rest-enumfield-0.2.0.tar.gz
- Upload date:
- Size: 3.0 kB
- Tags: Source
- Uploaded using 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
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | 0e3c1121e136dd7163c92737dcd67e0c6b78e78793b740b0811753343c7da8fe |
|
MD5 | c06eb094fbbcf55d3c1621ba459edec4 |
|
BLAKE2b-256 | 7dffab47c411c40253fd3fd66ebc04f2bd4e9034559f19d28aabef49f0f00689 |
File details
Details for the file django_rest_enumfield-0.2.0-py2.py3-none-any.whl
.
File metadata
- Download URL: django_rest_enumfield-0.2.0-py2.py3-none-any.whl
- Upload date:
- Size: 4.0 kB
- Tags: Python 2, Python 3
- Uploaded using 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
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | 80792326d5d8fad8a66729e9404a4078fe16f7eb8b2a910b37157d96df415611 |
|
MD5 | b3f55c6ea66fd41371570dfdc8154257 |
|
BLAKE2b-256 | 9c27e7b1b166a3e36983f73b49bfcb974e29f46807c3ebc1a2c5fc0ec0e8a8d9 |