#27910: Allow using an Enum class in model Field choices
-------------------------------------+-------------------------------------
Reporter: Marcel Hellwig | Owner: Shai
| Berger
Type: New feature | Status: assigned
Component: Database layer | Version: master
(models, ORM) |
Severity: Normal | Resolution:
Keywords: enum model choices | Triage Stage: Accepted
Has patch: 1 | Needs documentation: 0
Needs tests: 0 | Patch needs improvement: 0
Easy pickings: 0 | UI/UX: 0
-------------------------------------+-------------------------------------
Comment (by Luke Plant):
This ticket really ought to consider the use of database level enums for
the field. (e.g. https://www.postgresql.org/docs/9.1/datatype-enum.html ).
They provide a lot of efficiency (storage and searching), while allowing
the DB to contain human readable values (from the point of view of anyone
querying it), and also having tight data integrity - you get the best of
everything. MySQL also has support, but it looks a bit different.
[https://github.com/ashleywaite/django-more/tree/master/django_enum
django_enum] implements this, but it requires a significant number of
patches to Django machinery, which django_enum does by monkey patching. In
particular, you need to track changes to the enum in order to generate
'CREATE TYPE' and 'ALTER TYPE' (for Postgres at least). It would be great
to have a solution in Django core so that we could avoid that kind of
monkey patching.
We might want to consider this as a separate ticket, but it would be a
shame to solve the problem half-way. At the very least we should ensure
that the solution we adopt would be future compatible with using DB-level
enums.
There may well be some good ideas from
[https://techspot.zzzeek.org/2011/01/14/the-enum-recipe/ Mike Bayer's post
about enums] that we can make use of. His `DeclEnum` base class is very
similar in interface to `EnumChoices`, which is a good sign at least!
--
Ticket URL: <https://code.djangoproject.com/ticket/27910#comment:14>
Django <https://code.djangoproject.com/>
The Web framework for perfectionists with deadlines.
--
You received this message because you are subscribed to the Google Groups
"Django updates" group.
To unsubscribe from this group and stop receiving emails from it, send an email
to [email protected].
To post to this group, send email to [email protected].
To view this discussion on the web visit
https://groups.google.com/d/msgid/django-updates/066.930d5cf9df2ccf854bceecfa41e786fc%40djangoproject.com.
For more options, visit https://groups.google.com/d/optout.