Best way to add third attribute to Django models choices

Viewed 91

As the title suggests, what would be the best way to go about adding a third attribute to Django's model enum choice so that I could access the property in the same manner as value or label. For instance, let's call this third attribute text

what I want:

class Vehicle(models.Model):

    class VehicleType(??):
        HONDA_CIVIC = 1, _("New car"), _("Vroom vroom")
        FORD_MODEL_T = 2, _("Old car"), _("not so fast") 

    type = models.IntegerField(choices=VehicleType.choices, default=VehicleType.FORD_MODEL_T)


vehicle = Vehicle.objects.create()
vehicle.type.text
>>> not so fast

Is this possible without overwriting the base ChoicesMeta? I've tried a version as outlined in the python enum docs by updating __new__ however this doesn't seem to work. (And yes, I know I could change it to models.TextChoices and nix the int value, but I'm curious if this is easily possible)

0 Answers
Related