Count values grouped by date
Hi,
I have:
class BannerStats(models.Model):
ACTION_TYPE_VIEW = 0
ACTION_TYPE_CLICK = 1
ACTION_TYPES = (
(ACTION_TYPE_VIEW, 'view'),
(ACTION_TYPE_CLICK, 'click'),
)
banner = models.ForeignKey(
Banner
)
date = models.DateTimeField(
auto_now_add=True
)
action = models.PositiveSmallIntegerField(
choices=ACTION_TYPES,
default=ACTION_TYPE_VIEW
)
I need to get list of dates with sum of views and sum of clicks grouped by
date. I use:
BannerStats.objects.filter(
banner=banner
).extra(
{'date': 'date(date)'}
).values(
'date',
).annotate(
views=models.Count('id')
)
But this works only for vies, is there a way how can I get views and click
in one query? Or have I to do two queries and join it in Python? Or should
I remove action column and split it to views and clicks columns?
Thanks,
Martin
--
You received this message because you are subscribed to the Google Groups "Django users" group.
To post to this group, send email to django-users@googlegroups.com.
To unsubscribe from this group, send email to django-users+unsubscribe@googlegroups.com.
For more options, visit this group at http://groups.google.com/group/django-users?hl=en.
0 Comments:
Post a Comment
Subscribe to Post Comments [Atom]
<< Home