__copyright__ = "Copyright © Stichting SciPost (SciPost Foundation)"
__license__ = "AGPL v3"
import datetime
from django.db import models
[docs]class OrganizationQuerySet(models.QuerySet):
[docs] def with_subsidy_above_and_up_to(self, min_amount, max_amount=None):
"""
List of sponsors with at least one subsidy above parameter:amount.
"""
qs = self.annotate(max_subsidy=models.Max("subsidy__amount")).filter(
max_subsidy__gte=min_amount
)
if max_amount:
qs = qs.filter(max_subsidy__lt=max_amount)
return qs
[docs] def order_by_total_amount_received(self):
"""
Order by (decreasing) total amount received.
"""
return self.annotate(total=models.Sum("subsidy__amount")).order_by("-total")