Skip to content

Replace ChoiceEnum with models.TextChoices #1803

Description

@abkfenris

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)

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions