Hello there!
Is it possible to limit a SubQuery to a dynamic value of an instance in a
QuerySet? I.e. I'm looking for something like:
queryset =
model.objects.filter(field=OuterRef('field')).values('another_field')[:OuterRef('number')]
Sincerely,
Nick Gashkov
--
You received this message bec
Hello Nick,
It isn't possible to reference columns in a LIMIT clause AFAIK.
I'd suggest you use a RowNumber[0] window function ordered by your number
column in a
subquery and filter on the annotated value in the outer query.
Cheers,
Simon
[0]
https://docs.djangoproject.com/en/2.1/ref/models/d
Simon,
Thank you for fast reply! I've tried to rewrite a query using RowNumber()...
inner_subquery = queryset.objects.filter(date__gte=today,
day_type='working_day')
inner_subquery =
inner_subquery.annotate(row_number=Window(expression=RowNumber(),
order_by=F('number').asc()))
inner_subquery =
3 matches
Mail list logo