Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Save gregorynicholas/97fd96e2a679ff54ff539f094f81e32a to your computer and use it in GitHub Desktop.
Save gregorynicholas/97fd96e2a679ff54ff539f094f81e32a 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