#31512: Django TextChoices cannot utilize `is` or `==` isn't explicitly stated
-------------------------------------+-------------------------------------
Reporter: Casper | Owner: nobody
Weiss Bang |
Type: Bug | Status: new
Component: Database | Version: 3.0
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 |
-------------------------------------+-------------------------------------
i was reading about the "new" enums feature here:
https://docs.djangoproject.com/en/3.0/ref/models/fields/#enumeration-
types
And wanted to utilize it. However i tried to use `is` to check for
equality rather than `in`. That made it impossible to utilize before i
realized that the returned type from the CharField is, naturally, a char,
and that i could check for equality with `in`: `self.year_in_school in
self.YearInSchool.JUNIOR`
This probably isn't the most beautiful thing though, and it wasn't really
stated that this is the defacto way to check for equality (lest i use
`self.year_in_school in self.YearInSchool.JUNIOR.value`.
It would be quite nice if the `self.year_in_school` type actually was of
type ENUM, or atleast had documented how you could check for equality with
them.
The current solution seems, sadly, hacky at best.
--
Ticket URL: <https://code.djangoproject.com/ticket/31512>
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/047.de6c0903031c83a6ac80e2f8651cb643%40djangoproject.com.