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
You received this message because you are subscribed to the Google Groups "Django users" group.
To unsubscribe from this group and stop receiving emails from it, send an email to django-users+unsubscribe@googlegroups.com.
To post to this group, send email to django-users@googlegroups.com.
Visit this group at https://groups.google.com/group/django-users.
To view this discussion on the web visit https://groups.google.com/d/msgid/django-users/CAHSNPWsa_7RtWzopQdJa7NK_vzZtshMxMuPoc1Vsz9HiWu_GVA%40mail.gmail.com.
For more options, visit https://groups.google.com/d/optout.
No comments:
Post a Comment