def __init__(self, expression, distinct=False, **extra): if expression == '*': expression = Star() super(Count, self).__init__(expression, distinct='DISTINCT ' if distinct else '', output_field=IntegerField(), **extra)
def __init__(self, expression, filter=None, **extra): if expression == '*': expression = Star() if isinstance(expression, Star) and filter is not None: raise ValueError( 'Star cannot be used with filter. Please specify a field.') super().__init__(expression, filter=filter, **extra)
def get(self, request): currency_id = request.query_params.get("currency") customer_id = self.request.query_params.get("customer") currency = get_object_or_404( Currency.objects.select_related("business"), id=currency_id) business = currency.business customer = get_object_or_404(business.customers, id=customer_id) points = (Point.objects.filter( user=customer, currency=currency).values("created_at", "expires_at").order_by( "-created_at", "-expires_at").annotate(value=Count(Star()))) redemptions = (Redemption.objects.filter( user=customer, currency=currency).values("created_at", "reward", "value").order_by("-created_at")) # TODO: Preferably do this merging form the db instead of in Python. result = heapq.merge( points.iterator(), redemptions.iterator(), key=lambda row: row["created_at"], reverse=True, ) return Response(result)
def __init__(self, expression, distinct=False, filter=None, **extra): if expression == "*": expression = Star() if isinstance(expression, Star) and filter is not None: raise ValueError( "Star cannot be used with filter. Please specify a field.") super().__init__(expression, distinct="DISTINCT " if distinct else "", filter=filter, **extra)
def __init__(self, expression, distinct=False, filter=None, **extra): if expression == '*': expression = Star() if isinstance(expression, Star) and filter is not None: raise ValueError( 'Star cannot be used with filter. Please specify a field.') super().__init__(expression, distinct='DISTINCT ' if distinct else '', output_field=IntegerField(), filter=filter, **extra)
def __init__(self, expression, **extra): """ Overridden to check for filtering star expressions. :param expression: The SQL function expression :type expression: django.db.models.expressions.Expression | str :param extra: Additional keyword arguments to pass on :type extra: any """ expression = Star() if expression == "*" else expression has_filter = "filter" in extra and extra["filter"] is not None if isinstance(expression, Star) and has_filter: raise ValueError("Star cannot be used with filter.") Func.__init__(self, expression, filter=filter, **extra)
def __init__(self, expression, filter=None, **extra): if expression == '*': expression = Star() if isinstance(expression, Star) and filter is not None: