[Django] #36240: Store original choices Enum on the model field

6 views
Skip to first unread message

Django

unread,
Mar 10, 2025, 2:21:53 AMMar 10
to django-...@googlegroups.com
#36240: Store original choices Enum on the model field
-------------------------------------+-------------------------------------
Reporter: Evstifeev Roman | Type:
| Uncategorized
Status: new | Component: Database
| layer (models, ORM)
Version: 5.1 | Severity: Normal
Keywords: | Triage Stage:
| Unreviewed
Has patch: 0 | Needs documentation: 0
Needs tests: 0 | Patch needs improvement: 0
Easy pickings: 0 | UI/UX: 0
-------------------------------------+-------------------------------------
The models filed can have choices provided in ''Enum''
(django.db.models.Choices). This original ''Enum'' class can't be
retrieved from the field itself, as it only stores normalized list of
(value, label) tuples in its `field.choices` property.

It would be useful to be able to retrieve the original ''Enum'' from the
given model field during a process of building a json schema or pydantic
model. One example of such use is [https://github.com/vitalik/django-ninja
django-ninja] framework.

Currently it is possible to rebuild similar ''Enum'' from the field with
`field.choices` with `Enum('FieldChoices', field.choices)` but the
original Enum name and any additional meta info defined on it is lost.
--
Ticket URL: <https://code.djangoproject.com/ticket/36240>
Django <https://code.djangoproject.com/>
The Web framework for perfectionists with deadlines.

Django

unread,
Mar 10, 2025, 3:24:20 AMMar 10
to django-...@googlegroups.com
#36240: Store original choices Enum on the model field
-------------------------------------+-------------------------------------
Reporter: Evstifeev Roman | Owner: (none)
Type: New feature | Status: closed
Component: Database layer | Version: 5.1
(models, ORM) |
Severity: Normal | Resolution: wontfix
Keywords: | Triage Stage:
| Unreviewed
Has patch: 0 | Needs documentation: 0
Needs tests: 0 | Patch needs improvement: 0
Easy pickings: 0 | UI/UX: 0
-------------------------------------+-------------------------------------
Changes (by Sarah Boyce):

* resolution: => wontfix
* status: new => closed
* type: Uncategorized => New feature

Comment:

Hi

This appears to be requesting a new feature for Django. For cases like
this, the recommended path forward is to first propose and discuss the
idea with the community and gain consensus. To do that, please consider
starting a new conversation on the
[https://forum.djangoproject.com/c/internals/5 Django Forum], where you'll
reach a broader audience and receive additional feedback.

I'll close the ticket for now, but if the community agrees with the
proposal, please return to this ticket and reference the forum discussion
so we can re-open it. For more information, please refer to
[https://docs.djangoproject.com/en/stable/internals/contributing/bugs-and-
features/#requesting-features the documented guidelines for requesting
features].

Thanks!
--
Ticket URL: <https://code.djangoproject.com/ticket/36240#comment:1>
Reply all
Reply to author
Forward
0 new messages