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.2.tar.gz
Algorithm | Hash digest | |
---|---|---|
SHA256 | f0f7866e5bfdd665447a577dbc49a4a6ea83a2942312b2c5c64d35edd214805f |
|
MD5 | 81302efad831d1407841b20a37c3c187 |
|
BLAKE2b-256 | 2a1051b274119294189b6ff76157953643545dc1129e43562b910695d92f13eb |
Close
Hashes for django_rest_enumfield-0.1.2-py2.py3-none-any.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 30965e5269dc1b0de33354ebb85cb1363339394f749b4752e4fb08741fb59b6e |
|
MD5 | 849d05d906ad8aaaf6ad0179dcdff848 |
|
BLAKE2b-256 | d505c1ccc8bfe05c7d646d2385d928afc04c534148c6e055514c7ab954116c46 |