Skip to content

Instantly share code, notes, and snippets.

@gregtap
Created July 23, 2015 22:05
Show Gist options
  • Select an option

  • Save gregtap/c5ce8b6061c2fd694c76 to your computer and use it in GitHub Desktop.

Select an option

Save gregtap/c5ce8b6061c2fd694c76 to your computer and use it in GitHub Desktop.
Postgres Djagno date_trunc
qs = Foo.objects.filter(
type=0,
duration_minutes__gt=0,
created__gt=thirty_days_ago
)
qs = qs.extra({
'day': "date_trunc('day', foos_foo.created AT TIME ZONE 'America/Chicago')"
}).values('day').order_by().annotate(sum=Sum('duration_minutes'))
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment