Skip to content Skip to sidebar Skip to footer

Django Queryset Annotation, Charfield With Choices And Trying To Get The Display Value

The relevant bits of my model: class AnalyticRecord(models.Model): APP = 'APP' WEB = 'WEB' DASH = 'DASH' SOURCE_CHOICES = ( (APP, 'Mobile Application'),

Solution 1:

queryset = event.analyticrecord_set.all().values("source").\
    annotate(label=Concat("source", Value(None), output_field=CharField()))

for query in queryset:
    print(queryset.model(source=query['source']).get_source_display())

can you try above code snippet, hope this helps


Post a Comment for "Django Queryset Annotation, Charfield With Choices And Trying To Get The Display Value"