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.1.1.tar.gz
Algorithm | Hash digest | |
---|---|---|
SHA256 | a085fe68f220cad900d2f99613530c9283b8cfe02229c8a2722aa73e539b9315 |
|
MD5 | 14e261a3fbdad64a09f570c0fedfb531 |
|
BLAKE2b-256 | 80b9f3921ea5ca909eecd2806b3814e756a2663bac828ca901624096a08b41d1 |
Close
Hashes for django_rest_enumfield-0.1.1-py2.py3-none-any.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | fff37d35fb9d5e9a001fab2bfa7dc34eb92339bbb4aa2be359846cb0afb91d64 |
|
MD5 | 9476d87525119a790a815ee037213949 |
|
BLAKE2b-256 | 4233861e5c776addcd40a831297ab0b1f08fab41b4f7d057c5c27dd25892b951 |