[Fixed]-Set value in enum field

1👍

You can use django-choices package for behaviour like this. Using that, you can do:

class Car(models.Model):
    class CarType(DjangoChoices):
        SUV = ChoiceItem('something')
        BUS = C('something else')

    type = models.CharField(choices=CarType.choices, default=CarType.SUV, max_length=20)

And use it later like:

suvs = models.Car.objects.filter(type=models.Car.CarType.SUV)

Leave a comment