Skip to main content

A Django 1.7+ model field for use with Python 3 enums.

Project description

A Django 1.7+ model field for use with Python 3 enums.

Works with any enum whose values are integers. Subclasses the IntegerField to store the enum as integers in the database.

When creating/loading fixtures, values are serialized to dotted names, like “AnimalType.Cat” for the example below.

A decorator is needed on Python enums in order to make them work with Django migrations, which require a deconstruct() method on the enum members.

Installation:

pip install enum3field

Example:

import enum
from enum3field import EnumField, django_enum

@django_enum
class AnimalType(enum.Enum):
  Cat = 1
  Dog = 2
  Turtle = 3

class Animal(models.Model):
  animalType = EnumField(AnimalType)

Requires Python 3. Not tested with Django versions prior to 1.7 but might work.

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

enum3field-0.1.1.tar.gz (2.8 kB view details)

Uploaded Source

File details

Details for the file enum3field-0.1.1.tar.gz.

File metadata

  • Download URL: enum3field-0.1.1.tar.gz
  • Upload date:
  • Size: 2.8 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No

File hashes

Hashes for enum3field-0.1.1.tar.gz
Algorithm Hash digest
SHA256 ea6196d88bdd75313f38dbbdbc8acd0794c555f4f8ff46d96f407dcc082d6ea5
MD5 d92e83328ac98c1ee3b72857100e2916
BLAKE2b-256 028409ce87190cf19253c6da44837903eca05d3a2c48c3bd07b3975dfee1b321

See more details on using hashes here.

Supported by

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