1
It might archived querying from Payment
like this:
from django.db.models import Count, Q
users = Payment.objects.filter(
Q(date_updated__lte=time_until) &
Q(date_updated__gte=time_from) &
~Q(status=Payment.STATUS_COMPLETED)
).values('user').annotate(count=Count('pk'))
Or just:
from django.db.models import Count
users = Payment.objects.filter(
date_updated__lte=time_until,
date_updated__gte=time_from
).exclude(
status=Payment.STATUS_COMPLETED)
).values('user').annotate(count=Count('pk'))
(indentation might wrong)
Source:stackexchange.com