--
Ticket URL: <https://code.djangoproject.com/ticket/24342>
Django <https://code.djangoproject.com/>
The Web framework for perfectionists with deadlines.
* needs_docs: => 1
* needs_tests: => 1
* needs_better_patch: => 0
Comment:
This sounds like a good idea considering the new `enum` type in Python
3.4, but the `enum34` package would have to be added to Django's
requirements to support backwards compatibility for versions < 3.4.
Would this basically replace the need to use choices in `CharField`?
--
Ticket URL: <https://code.djangoproject.com/ticket/24342#comment:1>
* type: Uncategorized => New feature
--
Ticket URL: <https://code.djangoproject.com/ticket/24342#comment:2>
Comment (by ovangle):
For us, it has replaced the use of choices everywhere, although we don't
use django forms (django only powers our REST API). The enum names are
stored in the database column and the implementation is agnostic to the
enum values. Our implementation is currently postgres specific, but should
be relatively easily to make generic.
But there are (dubious) use cases supported by choices that can't be
easily filled by enums (such as defining named groups of values in a
`<select>` form element), so I don't think choices can be deprecated
entirely. Perhaps an optional `form_groups` argument to `EnumField` would
satisfy this use case if a decision to deprecate choices were made in
response to this.
--
Ticket URL: <https://code.djangoproject.com/ticket/24342#comment:3>
* version: 1.7 => master
--
Ticket URL: <https://code.djangoproject.com/ticket/24342#comment:4>
Comment (by timgraham):
Could you please raise the issue on the DevelopersMailingList to see if
there is consensus to add this to core?
--
Ticket URL: <https://code.djangoproject.com/ticket/24342#comment:5>
* needs_docs: 1 => 0
* needs_tests: 1 => 0
* stage: Unreviewed => Someday/Maybe
Comment:
The [https://groups.google.com/d/topic/django-
developers/whVe0_lZxs4/discussion mailing list thread] didn't reveal a
strong consensus to add this to core at this time. My sense is that it
might be more appealing once the minimum version of Python that Django
supports has enums (3.4+).
The mailing list thread also noted [https://github.com/hzdg/django-
enumfields django-enumfields] as an active third-party implementation.
--
Ticket URL: <https://code.djangoproject.com/ticket/24342#comment:6>
--
Ticket URL: <https://code.djangoproject.com/ticket/24342#comment:7>
Comment (by mmoreaux):
Replying to [comment:7 timgraham]:
> The mailing list thread also noted django-enumfields as an active
third-party implementation.
It's worth noting though that django-enumfields is CharField-based and
doesn't use the database-specific enum types. So it's not a full
replacement for the feature requested here.
--
Ticket URL: <https://code.djangoproject.com/ticket/24342#comment:8>
Comment (by frewsxcv):
If someone (maybe myself?) wrote a PostgreSQL specific `EnumField`, could
it be added to `django.contrib.postgres`?
--
Ticket URL: <https://code.djangoproject.com/ticket/24342#comment:9>
* cc: frewsxcv (added)
--
Ticket URL: <https://code.djangoproject.com/ticket/24342#comment:10>
Comment (by timgraham):
The idea of a PostgreSQL-specific field was rejected on the mailing list
thread link in comment:6. Quoting Josh Smeaton:
I definitely do not like the idea of building a feature into
contrib.postgres that could be built for the rest of the database backends
too. It seems like a cop-out for doing less work, and really promotes one
built in backend above others. contrib.postgres should be a place for
postgres specific features, not for cutting out other backends.
--
Ticket URL: <https://code.djangoproject.com/ticket/24342#comment:11>
* cc: andre@… (added)
--
Ticket URL: <https://code.djangoproject.com/ticket/24342#comment:12>
Comment (by Anton Agestam):
Now that the next version of Django will drop support for Python versions
<3.5, will pull requests for this feature be considered?
Also thought it was worth mentioning https://github.com/5monkeys/django-
enumfield although it seems like it's no longer maintained and lacks
support from Django 1.8.
--
Ticket URL: <https://code.djangoproject.com/ticket/24342#comment:13>
Comment (by Tim Graham):
Yes, a patch would certainly help advance the conversation -- particularly
if you can highlight the advantages of this as part of Django rather than
as a third-party package.
--
Ticket URL: <https://code.djangoproject.com/ticket/24342#comment:14>
Comment (by Mahmoud Hossam):
I'm interested in implementing this feature, but I have a question
regarding backend support.
MySQL and PostgreSQL both have native types to support this feature, but
SQLite and Oracle don't.
How should we go about supporting this feature on those two databases?
--
Ticket URL: <https://code.djangoproject.com/ticket/24342#comment:15>
Comment (by Ashley Waite):
I've implemented a POC that uses postgres and mysql enums (and will add a
fail to char for others) handling all the migrations cases (changing enum,
adding/removing values, etc).
https://github.com/ashleywaite/django-more/tree/master/django_enum
Is a pull to add these changes something that will be considered?
--
Ticket URL: <https://code.djangoproject.com/ticket/24342#comment:16>
* component: Database layer (models, ORM) => HTTP handling
* stage: Someday/Maybe => Accepted
Comment:
Yes, please!
--
Ticket URL: <https://code.djangoproject.com/ticket/24342#comment:17>
* component: HTTP handling => Database layer (models, ORM)
* stage: Accepted => Someday/Maybe
--
Ticket URL: <https://code.djangoproject.com/ticket/24342#comment:18>
* cc: Tom Forbes (added)
--
Ticket URL: <https://code.djangoproject.com/ticket/24342#comment:19>
* cc: Krzysztof Szularz (added)
--
Ticket URL: <https://code.djangoproject.com/ticket/24342#comment:20>
* cc: Olivier Tabone (added)
--
Ticket URL: <https://code.djangoproject.com/ticket/24342#comment:21>
* cc: Kye Russell (added)
--
Ticket URL: <https://code.djangoproject.com/ticket/24342#comment:22>
* cc: Semyon Pupkov (added)
--
Ticket URL: <https://code.djangoproject.com/ticket/24342#comment:23>
* cc: Stefan Foulis (added)
--
Ticket URL: <https://code.djangoproject.com/ticket/24342#comment:24>
* cc: Ryan Hiebert (added)
--
Ticket URL: <https://code.djangoproject.com/ticket/24342#comment:25>
* cc: safwanrahman (added)
--
Ticket URL: <https://code.djangoproject.com/ticket/24342#comment:26>
* cc: Sévastien Fievet (added)
--
Ticket URL: <https://code.djangoproject.com/ticket/24342#comment:27>
* cc: Paolo Melchiorre (added)
Old description:
> Add support for an `EnumField` which is backed by the corresponding
> `enum` type if one exists in the database engine (eg. mysql, postgres),
> with a default implementation of CharField in other database types and
> mapped to instances of the `enum.Enum` (or `enum34.Enum` in python 2).
New description:
Add support for an `EnumField` which is backed by the corresponding `enum`
type if one exists in the database engine (eg. mysql, postgres), with a
default implementation of CharField in other database types and mapped to
instances of the `enum.Enum`.
--
--
Ticket URL: <https://code.djangoproject.com/ticket/24342#comment:28>
* cc: Cesar Canassa (added)
--
Ticket URL: <https://code.djangoproject.com/ticket/24342#comment:29>
* cc: Duane Hutchins (added)
--
Ticket URL: <https://code.djangoproject.com/ticket/24342#comment:30>
* cc: Hannes Ljungberg (added)
--
Ticket URL: <https://code.djangoproject.com/ticket/24342#comment:31>
* cc: Adam (Chainz) Johnson (added)
--
Ticket URL: <https://code.djangoproject.com/ticket/24342#comment:32>
Comment (by Adam (Chainz) Johnson):
I have a MariaDB/MySQL stable implementation which I've used many times in
production. It can provide a starting point: https://django-
mysql.readthedocs.io/en/latest/model_fields/enum_field.html
--
Ticket URL: <https://code.djangoproject.com/ticket/24342#comment:33>
Comment (by Carlton Gibson):
#31861 was a duplicate. Maybe the position is advanced some by the enum
choices available since 3.0.
Tim's comment:14 stills seems telling: a 3rd-party package showing what's
feasible is the first/next step, then a discussion of whether to bring
that into core.
(Wondering if this is wontfix pending such... 🤔)
--
Ticket URL: <https://code.djangoproject.com/ticket/24342#comment:34>
* cc: George Sakkis (added)
--
Ticket URL: <https://code.djangoproject.com/ticket/24342#comment:35>
* cc: Olivier Dalang (added)
--
Ticket URL: <https://code.djangoproject.com/ticket/24342#comment:37>