Opened 2 years ago
Closed 2 years ago
#33916 closed New feature (fixed)
Support for serialization of combination of Enum flags.
Reported by: | Willem Van Onsem | Owned by: | Willem Van Onsem |
---|---|---|---|
Component: | Migrations | Version: | 4.0 |
Severity: | Normal | Keywords: | |
Cc: | Triage Stage: | Ready for checkin | |
Has patch: | yes | Needs documentation: | no |
Needs tests: | no | Patch needs improvement: | no |
Easy pickings: | no | UI/UX: | no |
Description (last modified by )
If we work with a field:
regex_flags = models.IntegerField(default=re.UNICODE | re.IGNORECASE)
This is turned into a migration with:
default=re.RegexFlag[None]
This is due to the fact that the EnumSerializer
aims to work with the .name
of the item, but if there is no single item for the given value, then there is no such name.
In that case, we can use enum._decompose
to obtain a list of names, and create an expression to create the enum value by "ORing" the items together.
Attachments (1)
Change History (8)
by , 2 years ago
Attachment: | enum_serializer.patch added |
---|
comment:1 by , 2 years ago
Description: | modified (diff) |
---|
comment:2 by , 2 years ago
Owner: | changed from | to
---|---|
Status: | new → assigned |
Summary: | default does not work for enums with flags if two or more items are used. → Support for serialization of combination of Enum flags. |
Triage Stage: | Unreviewed → Accepted |
Type: | Uncategorized → Bug |
comment:6 by , 2 years ago
Needs documentation: | unset |
---|---|
Patch needs improvement: | unset |
Triage Stage: | Accepted → Ready for checkin |
Note:
See TracTickets
for help on using tickets.
patch of the EnumSerializer