#31261: Add support for defining Enum fields with dict, tuple, set and list 
values
-------------------------------------+-------------------------------------
               Reporter:  Tom        |          Owner:  nobody
  Forbes                             |
                   Type:  New        |         Status:  new
  feature                            |
              Component:  Database   |        Version:  master
  layer (models, ORM)                |
               Severity:  Normal     |       Keywords:
           Triage Stage:             |      Has patch:  0
  Unreviewed                         |
    Needs documentation:  0          |    Needs tests:  0
Patch needs improvement:  0          |  Easy pickings:  0
                  UI/UX:  0          |
-------------------------------------+-------------------------------------
 As per the discussion on this forum post:
 https://forum.djangoproject.com/t/moving-to-django-3-0s-field-choices-
 enumeration-types/970/8

 It would be good to support two fairly common use cases with Enums:
 defining groups of related values (groups), and defining grouping for use
 with specific widgets.

 One way to enable both of these would be to simply special-case enum
 values with `dict`, `tuple`, `set` and `list` values:


 {{{
 class MoonMissions(Enum):
     APOLLO_10 = 1
     APOLLO_11 = 2
     EXPLORER_33 = 3

     FAILED_MISSIONS = {EXPLORER_33}
     SUCCESSFUL_MISSIONS = (APOLLO_10, APOLLO_11)

     SUCCESS_GROUPING = {
         "Failed": FAILED_MISSIONS,
         "Successful": SUCCESSFUL_MISSIONS
     }

     COUNTRY_GROUPING = [
          ["USA", [APOLLO_10, APOLLO_11, EXPLORER_33]]
     ]
 }}}

 Now a user can do:


 {{{
 SomeModel.objects.filter(mission__in=MoonMissions.FAILED_MISSIONS)
 enum_form_field.value in MoonMissions.SUCCESSFUL_MISSIONS
 models.IntegerField(choices=MoonMissions.COUNTRY_GROUPING)
 }}}

-- 
Ticket URL: <https://code.djangoproject.com/ticket/31261>
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 view this discussion on the web visit 
https://groups.google.com/d/msgid/django-updates/046.852143845c8c7a90d378c41f96315a8d%40djangoproject.com.

Reply via email to