I am trying to query a queryset in Django using annotate to get a calculation for each different 'field2'. The query looks like:
offer_lines.filter('field1'=x).order_by().values('field2').annotate(
total=F('field3') * F('field4')
While I am expecting it to return something that looks like this:
[{'field2_value1': '1'}, {'field2_value2': '2'}]
I am getting multiple entries for the same field2 value. So it looks more like this:
[{'field2_value1': '1'}, {'field2_value1': '2'}, {'field2_value1': '5'},{'field2_value2': '2'}, {'field2_value2': '1'}]
I have order_by() in the query as I saw in other questions that it sometimes matters, but it did not help me. How can I query it to only return one entry per each unique field2 value?