Opened 5 years ago
Closed 5 years ago
#31512 closed Bug (invalid)
Django TextChoices cannot utilize `is` or `==` isn't explicitly stated
Reported by: | Casper Weiss Bang | Owned by: | nobody |
---|---|---|---|
Component: | Database layer (models, ORM) | Version: | 3.0 |
Severity: | Normal | Keywords: | |
Cc: | Triage Stage: | Unreviewed | |
Has patch: | no | Needs documentation: | no |
Needs tests: | no | Patch needs improvement: | no |
Easy pickings: | no | UI/UX: | no |
Description (last modified by )
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 at least had documented how you could check for equality with them.
The current solution seems, sadly, hacky at best.
Change History (1)
comment:1 by , 5 years ago
Description: | modified (diff) |
---|---|
Resolution: | → invalid |
Status: | new → closed |
==
works properly for me, e.g.I wouldn't expect that
is
will work here.Please try to be more polite and appreciate the effort of contributors.