1
Does anyone there have an example of a "bat-ready" grouping by date? I tried all this here...
Subscription.objects.extra(select={'day': 'date(created_at)'}).values('day').annotate(available=Count('created_at'))
from django.db.models.aggregates import Count
Subscription.objects.extra({'date':"date(created_at)"}).values('date').annotate(count=Count('id'))
from django.db import connection
from django.db.models import Count
select = {'day': connection.ops.date_trunc_sql('day', 'created_at')}
Subscription.objects.extra(select=select).values('day').annotate(number=Count('id'))
But none returned what I want:
2016-01-22, 10
2016-01-21, 5
2016-01-15, 7
It’s like Datetimefield and it’s counting one by one, it’s not grouping. I said I need to group by day?
– Regis Santos
@Regisdasilva if the guy is
datefield
it will group by day, need not extract the day of thedate
. I added a way to group bydate
if it is adatetime
.– Paulo
it is not grouping by day, it is returning number=1 for each date, but it was to return day 22, 3; 21, 10 for example.
– Regis Santos
@Regisdasilva here is working
– Paulo
@Regisdasilva added another solution.
– Paulo
Strange, none of the solutions worked. Ah, check my github https://github.com/rg3915/wttd2/blob/master/eventex/subscriptions/models.py#L11 that the field is Datetimefield. I’m wearing Django 1.9.1
– Regis Santos
@Regisdasilva the problem is not in the code, maybe you have not registered anything, or there are no registrations on the same day, what I put is all correct and working 100%.
– Paulo
@Regisdasilva what error is appearing?
– Paulo
Let’s go continue this discussion in chat.
– Regis Santos