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

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


Download files

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

Source Distribution

django-rest-enumfield-0.1.2.tar.gz (3.0 kB view details)

Uploaded Source

Built Distribution

django_rest_enumfield-0.1.2-py2.py3-none-any.whl (4.1 kB view details)

Uploaded Python 2Python 3

File details

Details for the file django-rest-enumfield-0.1.2.tar.gz.

File metadata

  • Download URL: django-rest-enumfield-0.1.2.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.22.0 setuptools/41.0.1 requests-toolbelt/0.9.1 tqdm/4.32.2 CPython/3.7.3

File hashes

Hashes for django-rest-enumfield-0.1.2.tar.gz
Algorithm Hash digest
SHA256 f0f7866e5bfdd665447a577dbc49a4a6ea83a2942312b2c5c64d35edd214805f
MD5 81302efad831d1407841b20a37c3c187
BLAKE2b-256 2a1051b274119294189b6ff76157953643545dc1129e43562b910695d92f13eb

See more details on using hashes here.

File details

Details for the file django_rest_enumfield-0.1.2-py2.py3-none-any.whl.

File metadata

  • Download URL: django_rest_enumfield-0.1.2-py2.py3-none-any.whl
  • Upload date:
  • Size: 4.1 kB
  • Tags: Python 2, Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/1.13.0 pkginfo/1.5.0.1 requests/2.22.0 setuptools/41.0.1 requests-toolbelt/0.9.1 tqdm/4.32.2 CPython/3.7.3

File hashes

Hashes for django_rest_enumfield-0.1.2-py2.py3-none-any.whl
Algorithm Hash digest
SHA256 30965e5269dc1b0de33354ebb85cb1363339394f749b4752e4fb08741fb59b6e
MD5 849d05d906ad8aaaf6ad0179dcdff848
BLAKE2b-256 d505c1ccc8bfe05c7d646d2385d928afc04c534148c6e055514c7ab954116c46

See more details on using hashes here.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page