Skip to content

Instantly share code, notes, and snippets.

@jessamynsmith
Created October 28, 2015 13:42
Show Gist options
  • Save jessamynsmith/2a92920f011c382370e0 to your computer and use it in GitHub Desktop.
Save jessamynsmith/2a92920f011c382370e0 to your computer and use it in GitHub Desktop.
Using Django aggregates
from codementor import models as codementor_models
from django.db.models import Sum
payments = codementor_models.Payment.objects.all().order_by('date')
payments.count()
payments[:5]
payment_values = payments.values_list('date').annotate(total_earnings=Sum('earnings'))
payment_values.count()
payment_values[:5]
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment