Skip to main content

EnumField for Django REST Framework

Project description

Django REST EnumField

Build Status PyPI version Coveralls Status Black

EnumField that uses python enums for Django REST Framework


pip install django-rest-enumfield


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,, to_repr=lambda x: x.value)

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

Thats it.

Project details

Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Files for django-rest-enumfield, version 0.2.0
Filename, size File type Python version Upload date Hashes
Filename, size django_rest_enumfield-0.2.0-py2.py3-none-any.whl (4.0 kB) File type Wheel Python version py2.py3 Upload date Hashes View
Filename, size django-rest-enumfield-0.2.0.tar.gz (3.0 kB) File type Source Python version None Upload date Hashes View

Supported by

Pingdom Pingdom Monitoring Google Google Object Storage and Download Analytics Sentry Sentry Error logging AWS AWS Cloud computing DataDog DataDog Monitoring Fastly Fastly CDN DigiCert DigiCert EV certificate StatusPage StatusPage Status page