Hi everyone, I come late to the party and only noticed that Django now has support for enums on the 3.0 release notes. As I'm not a core developer I never imagined this.
I've wrote a lib that does something similar in mid-2018: https://github.com/loggi/python-choicesenum There's one main diff from the Python default behaviour: The default enum requires that you compare the enum against their value, something like `assert EnumClass.EnumItem.value == 3`, my custom implementation allow usage with `assert EnumClass.EnumItem == 3`, the expected behaviour IMHO. Thanks for your hard work! Em sábado, 13 de abril de 2019 11:00:47 UTC-3, Tom Forbes escreveu: > > I really like this implementation, it seems really clean and simple. > > I would suggest that it might be worth seeing it’s simple to make the > display text optional, I think in the general case capitalising the key > name would be acceptable. Users can always override it if required or if > they need translation support. > > Even if we decide to make the display names required in all cases, it’s a > great improvement over the current way of defining choices IMO. > > Tom > > > > > On 13 April 2019 at 10:33:39, Shai Berger ([email protected] > <javascript:>) wrote: > > Back to this issue for the DjangoCon EU sprints... > > James' objection about the inclusion testing needed for validation > seems moot, because validation can be done by conversion to the enum > type (as noted by Tom). > > Raphael's warning about the woes of translation are already handled by > the suggested implementation -- because it isn't the enum value that > we make translatable, but rather an attribute on it. > > I should point that the suggested implementation uses IntEnum and > StrEnum. The Python documentation recommends against using these, > except in the case that one needs to account for compatibility with an > existing protocol -- which, I submit to you, is exactly our case (the > "protocol" being the types available for database fields). > > As a reminder, the relevant links are: > > https://code.djangoproject.com/ticket/27910 > > https://github.com/django/django/compare/master...shaib:ticket_27910?expand=1 > > Thanks, > Shai. > > -- > You received this message because you are subscribed to the Google Groups > "Django developers (Contributions to Django itself)" group. > To unsubscribe from this group and stop receiving emails from it, send an > email to [email protected] <javascript:>. > To post to this group, send email to [email protected] > <javascript:>. > Visit this group at https://groups.google.com/group/django-developers. > To view this discussion on the web visit > https://groups.google.com/d/msgid/django-developers/20190413113323.1342ed7d.shai%40platonix.com. > > > For more options, visit https://groups.google.com/d/optout. > > -- You received this message because you are subscribed to the Google Groups "Django developers (Contributions to Django itself)" 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-developers/97fe821e-ab06-4dc1-95a6-276b25a42f07%40googlegroups.com.
