django-intenumfield

An IntEnumField for Django


Keywords
django, enum, enum34, python
License
MIT
Install
pip install django-intenumfield==1.4.0

Documentation

Django IntEnumField

Build Status

An IntEnumField for Django.

Features

  • Store your multiple-choice options as a smallint (2 bytes) instead of varchar
  • Reuse existing IntEnums as choice values
  • Integrates well with Django's admin app (display and filter)

Requirements

  • Python 2.7+ or 3.4+
  • Django 1.11+
  • enum34 library on Python 2.x

Usage

from enum import IntEnum
from django.db import models
from django_intenum import IntEnumField


class Status(IntEnum):
	UNKNOWN = 0
	IN_PROGRESS = 1
	COMPLETED = 2
	ERROR = 3


class Job(models.Model):
	status = IntEnumField(enum=Status)

License

This project is licensed under the MIT license. The full license text is available in the LICENSE file.