Re: Request to reconsider ticket #27910: using an Enum class in model Field choices

2019-01-14 Thread raphael
I saw this thread so wanted to share a bit of a gotcha we had with enums internally for anyone trying to handle this stuff Internally, we have a wrapper around CharField to work with enums (we go further than just choices and actually have the values be enums), but there's unfortunately still

Re: Request to reconsider ticket #27910: using an Enum class in model Field choices

2019-01-12 Thread Tom Forbes
While I agree that Enum’s are a bit clunky (and IMO removing in is a poor choice), is this going to really take be that hard to work with or that difficult to validate? Enums are types that raise ValueError, like any other, so it’s not that confusing and fits in with Django’s existing validation

Re: Request to reconsider ticket #27910: using an Enum class in model Field choices

2019-01-11 Thread James Bennett
Shai, your rebuttal still misses an important use case, which is containment. To continue with your example of a 'SchoolYear(str, Enum)', the following will both be False: 'FR' in SchoolYear 'FR' in SchoolYear.__members__ The first of those is also becoming illegal soon -- attempting an 'in'

Re: Request to reconsider ticket #27910: using an Enum class in model Field choices

2019-01-11 Thread Luke Plant
I've also tried to come up with something better than Django's current default, using Enums, and found them lacking when it comes to the caption, especially when you need translations. I would be happy with re-opening the ticket, but in terms of committing a solution I would be -1 unless we

Re: Request to reconsider ticket #27910: using an Enum class in model Field choices

2019-01-11 Thread Shai Berger
On Mon, 31 Dec 2018 23:40:53 + Tom Forbes wrote: > > We currently have a -1 and a +1, does anyone else have any input on > this? > So, the tally is +3, -1, and the -1 seems to be based on a technical argument which I believe I refuted; and more than a week has passed with no further

Re: Request to reconsider ticket #27910: using an Enum class in model Field choices

2018-12-31 Thread Ryan Hiebert
I would also love to see a decent way to use enums as choices. The translation issues seem the stickiest to me, but I'm kinda hoping we can come up with something reasonable. I'm a heavy user, but mostly a lurker on this list, but +1 from me for what it's worth. Ryan On Mon, Dec 31, 2018, 17:41

Re: Request to reconsider ticket #27910: using an Enum class in model Field choices

2018-12-31 Thread Tom Forbes
Unfortunately I made this for a python 2 app before enums where in the standard library. I think it has some useful ideas though especially around categories, which I find I needed a lot. I'd be interested to know if anyone else has written any workflow-driven apps in Django that require groups of

Re: Request to reconsider ticket #27910: using an Enum class in model Field choices

2018-12-31 Thread Shai Berger
Hi Tom, On Mon, 31 Dec 2018 18:26:14 + Tom Forbes wrote: > I was describing my django-choice-object library[1] and forgot to > link it! > Thanks, I took a look -- the library looks nice, but notably, Choice objects are not Python enums, although they share some of their traits. > I would

Re: Request to reconsider ticket #27910: using an Enum class in model Field choices

2018-12-31 Thread Shai Berger
Hi James, On Mon, 31 Dec 2018 10:24:39 -0800 James Bennett wrote: > The basic problem is that, to take the example in the ticket, if I > were to issue a request like "/students/?year=FR", and the view were > to read that "year" param and try to filter on it, it would fail -- > the string "FR"

Re: Request to reconsider ticket #27910: using an Enum class in model Field choices

2018-12-31 Thread Tom Forbes
Hey Shai, I have not had a chance to look at the implementation, but I was describing my django-choice-object library[1] and forgot to link it! I would be +1 on re-opening it, I've used enums for this before and I find it much more DRY than the more 'standard' Django way. Perhaps we could reduce

Re: Request to reconsider ticket #27910: using an Enum class in model Field choices

2018-12-31 Thread James Bennett
FWIW I'm pretty strongly -1 on this feature because Python's enums don't behave the way people want them to for many use cases. The basic problem is that, to take the example in the ticket, if I were to issue a request like "/students/?year=FR", and the view were to read that "year" param and try