You can limit your search by year, month or day.

See http://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-us...@googlegroups.com.
To unsubscribe from this group, send email to 
django-users+unsubscr...@googlegroups.com.
For more options, visit this group at 
http://groups.google.com/group/django-users?hl=.


Reply via email to