I’m using TextChoices
to define Food category - see this example:
class CategoryChoice(models.TextChoices):
# Fruits: T01-T50
T01 = 'T01', 'Apple'
T02 = 'T02', 'Banana'
T03 = 'T03', 'Blackberries'
T04 = 'T04', 'Cherries'
T05 = 'T05', 'Cranberries'
# Vegatables: T41-T60
T41 = 'T41', 'Asparagus'
T42 = 'T42', 'Broccoli'
T43 = 'T43', 'Carrot'
# Meat: T61-T99
T61 = 'T61', 'Beef'
T62 = 'T62', 'Lamb'
T63 = 'T63', 'Pork'
class Food(models.Model):
name = models.CharField(max_length=30)
category = models.CharField(
max_length=3,
choices=CategoryChoice.choices,
default=CategoryChoice.T01
)
How can I properly query only Food objects which have category between T41 and T60 using Food.objects.filter()
?