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
Close
Hashes for django-rest-enumfield-0.2.0.tar.gz
Algorithm | Hash digest | |
---|---|---|
SHA256 | 0e3c1121e136dd7163c92737dcd67e0c6b78e78793b740b0811753343c7da8fe |
|
MD5 | c06eb094fbbcf55d3c1621ba459edec4 |
|
BLAKE2b-256 | 7dffab47c411c40253fd3fd66ebc04f2bd4e9034559f19d28aabef49f0f00689 |
Close
Hashes for django_rest_enumfield-0.2.0-py2.py3-none-any.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 80792326d5d8fad8a66729e9404a4078fe16f7eb8b2a910b37157d96df415611 |
|
MD5 | b3f55c6ea66fd41371570dfdc8154257 |
|
BLAKE2b-256 | 9c27e7b1b166a3e36983f73b49bfcb974e29f46807c3ebc1a2c5fc0ec0e8a8d9 |