0

I have this data on the model:

[
  {"Field": "value1", "Flag": true},
  {"Field": "value2", "Flag": false},
  {"Field": "value1", "Flag": true},
  {"Field": "value2", "Flag": true},
  {"Field": "value1", "Flag": false},
  {"Field": "value2", "Flag": false},
  {"Field": "value1", "Flag": false}
]

I try to aggregate the data with this query when the flag is True:

model.objects.values('Field').order_by('Field').annotate(total=Count('Field'), Flag_field=Count('Flag', filter=Q(Flag=True)))

And I expect this output in the result of the query:

[
   {"Field": "value1", "total": 4, "Flag": 2},
   {"Field": "value2", "total": 3, "Flag": 1}
]

try with conditional aggregation but display this error:

SQLDecodeError

0 Answers0