Skip to content

Instantly share code, notes, and snippets.

@vkgtaro
Created November 22, 2012 09:29
Show Gist options
  • Select an option

  • Save vkgtaro/4130198 to your computer and use it in GitHub Desktop.

Select an option

Save vkgtaro/4130198 to your computer and use it in GitHub Desktop.
from apps.appname.models import Receivable
from django.db.models import Sum
receivable = Receivable.objects.all()
receivable.query.group_by = ['client_id']
receivable.annotate( total_price = Sum('price') )
SELECT client_id, sum(price_total) as total FROM appname_receivable group by client_id;
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment