[Answered ]-Django: Filter by less verbose (database name) on TextChoices class

1๐Ÿ‘

โœ…

I believe you can do following:

china_code = list(filter(lambda x: x[1] == 'China', RegulationModel.Market.choices)).pop()[1]
regulation = RegulationModel.objects.get(market=china_code)

But it is a bit hacky. I recommend using django-useful and its implementation of Choices.

๐Ÿ‘คpe.kne

Leave a comment