Django doesn't support this level of control over database queries - generally, you can't make queries use functions like CAST.
You have a few options in this case, though. First of all, most simply, you can just take the datetime object returned by the ORM object and remove the extra precision using datetime.replace()
.
Another option, if you know that you'll never want your Django app to use any precision in the updated field beyond the day, is to simply define updated
in your models.py as a models.DateField()
as opposed to models.DateTimeField()
. This means data returned by the ORM Model will never have precision beyond the day.
Finally, I assume you're using the most recent Django (1.1), but in Django 1.2 (scheduled for May 10), you'll be able to do the following:
Foobar.objects.raw("select updater, cast(updated as date), count(id) from foobar group by updater, cast(updated as date)")
The result (assuming it has the same number of columns and column types as what you've defined in your Foobar model) will be a normal django ORM Queryset.