Re: Count by date
i believe the way filters work (what martin referenced) is that you
have to explicitly say which weekday you care about.
what the op is looking for is a way to group by week day. ideally to
write something like MyTable.objects.values(created__week_day).annotate
(Count('id'))
however, this doesn't work as created__week_day is not a valid
argument to values. any ideas how to actually do this?
On Nov 23, 8:52 am, Martin Ostrovsky <martin.ostrov...@gmail.com>
wrote:
> You can limit your search by year, month or day.
>
> Seehttp://docs.djangoproject.com/en/dev/ref/models/querysets/#year
>
> On Nov 20, 1:59 pm, Simon <shar...@demodia.com> wrote:
>
> > Hi all,
>
> > I am sure this must be a real noob question as it's so easy to do in
> > SQL.
> > I am trying to replicate something like the following in Django:
>
> > SELECT DATE(created) AS created_day, COUNT(id) AS NumberOf FROM
> > my_table GROUP BY created_day
>
> > Effectively, all I want to do is a count grouped by a specific day,
> > week or month.
> > I assumed I could use something like
>
> > MyTable.objects.annotate(Count('created'))
>
> > but I can't find a way to format the "created" date such that it
> > ignores the less significant elements, such as the hours and minutes
> > and only counts entries based on the unit I want.
>
> > Anyone any ideas how to do this?
> > Thanks
--
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