#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.