class Ticket(models.Model):
...
booked_at = models.DateTimeField(default=timezone.now)
bought = models.BooleanField(default=False)
I would like to group tickets by booked day to get list of ticket or ticket's id for each day. Something like this:
[
{
'day': datetime.datetime(2018, 5, 6, 0, 0, ...>),
'ticket_list': [1, 2, 3, 4],
},
{
'day': datetime.datetime(2018, 5, 7, 0, 0, ...>),
'ticket_list': [5, 6, 7, 8, 9], }
]
I could group tickets by day this way and count total tickets per day,
Ticket.objects.filter(bought=True).annotate(day=TruncDay('booked_at')).values('day').annotate(c=Count('id')).order_by()
But I cannot figure out how to group by day and return ticket objects for that day. Could you please help me solve this.
Thank you