I have a table that contains orders, in which contains the date column. I am getting back the aggregate of the years, and months from that column so that I can use that data in a filter on the front end.
I have managed to get this data back, however it is not formatted in the way I would like.
Python
years = purchase_orders.objects.filter(user_id=info.context.user.id).annotate(year=ExtractYear('date'), month=ExtractMonth('date'),).order_by().values_list('year', 'month').order_by('year', 'month').distinct()
Data Returned
<QuerySet [(2020, 3), (2021, 4), (2022, 1), (2022, 2), (2022, 3), (2022, 4), (2022, 5)]>
Ideal Format
<QuerySet [(2020, (3)), (2021, (4)), (2022, (1, 2, 3, 4, 5))]>