﻿id	summary	reporter	owner	description	type	status	component	version	severity	resolution	keywords	cc	stage	has_patch	needs_docs	needs_tests	needs_better_patch	easy	ui_ux
27910	Allow using an Enum class in model Field choices	Marcel Hellwig	Nick Pope	"I will simply stick to your example here: https://docs.djangoproject.com/en/dev/ref/models/fields/#choices

I want to limit the input to certain choices so I create a list/tuple of tuples/lists. Since Python 3.4 there is a class called [https://docs.python.org/3.5/library/enum.html Enum] and some nice decorators like [https://docs.python.org/3.5/library/enum.html#ensuring-unique-enumeration-values @unique].

Currently, if you want to use this you have to do 1/2 dirty hacks, descriped in [http://blog.richard.do/index.php/2014/02/how-to-use-enums-for-django-field-choices/ this article], which I would prefer over the current solution.

It would be nice to have native support for the Enum class, e.g. you can directly pass the class to choices (instead of using the class method choices() ), also when refering to an element in the enum just using {{{Student.Freshmann}}} instead of {{{Student.Freshmann.value}}}

A simple example would be this:

{{{
from enum import Enum

class Student(models.Model):
    class YearInSchoolChoices(Enum):
        Freshman = 'FR'
        Sophomore = 'SO'
        Junior = 'JR'
        Senior = 'SR'
    
    year_in_school = models.CharField(
        max_length=2,
        choices=YearInSchoolChoices,
        default=YearInSchoolChoices.Freshman,
    )

    def is_upperclass(self):
        return self.year_in_school in (self.YearInSchoolChoices.Junior, self.YearInSchoolChoices.Senior)

}}}


Also this could be adopted (if accepted) to any type of choices in django, e.g. [https://docs.djangoproject.com/en/1.10/ref/forms/fields/#choicefield Choicefield] etc."	New feature	closed	Database layer (models, ORM)	dev	Normal	fixed	enum model choices	Tom Forbes Ryan Hiebert	Accepted	1	0	0	0	0	0
