models/choice_enum.py is a hand-rolled enum.Enum + choices() classmethod that predates models.TextChoices. This codebase already uses TextChoices for Platform.PlatformTypes (platform.py:18), TimeSeries.TimeSeriesType (timeseries.py:31), and TimeSeries.Highlighted (:46) — so ChoiceEnum is the odd one out, used only by Alert.Level and FloodLevel.Level.
Converting both:
- fixes the
Alert.level bug filed separately in this batch structurally rather than patching one instance (a plain Enum member stringifies to 'Level.INFO' when used as a field default; TextChoices members stringify to their value);
- lets the built-in
get_level_display() replace the manual FloodLevel.Level[fl.level].value lookups at serializers.py:51 and flood_level.py:32;
- deletes
choice_enum.py entirely.
Needs a migration (choices= change) plus the data repair for existing 'Level.INFO' rows. Values stay the member names, so no column type change.
(from #1781)
models/choice_enum.pyis a hand-rolledenum.Enum+choices()classmethod that predatesmodels.TextChoices. This codebase already usesTextChoicesforPlatform.PlatformTypes(platform.py:18),TimeSeries.TimeSeriesType(timeseries.py:31), andTimeSeries.Highlighted(:46) — soChoiceEnumis the odd one out, used only byAlert.LevelandFloodLevel.Level.Converting both:
Alert.levelbug filed separately in this batch structurally rather than patching one instance (a plainEnummember stringifies to'Level.INFO'when used as a field default;TextChoicesmembers stringify to their value);get_level_display()replace the manualFloodLevel.Level[fl.level].valuelookups atserializers.py:51andflood_level.py:32;choice_enum.pyentirely.Needs a migration (
choices=change) plus the data repair for existing'Level.INFO'rows. Values stay the member names, so no column type change.(from #1781)