Another solution is Common Table Expressions (CTE), and with the help of django-cte, you could achieve what you want:
cte = With(
YouModel.objects.annotate(
your_window_function=Window(...),
)
)
qs = cte.queryset().with_cte(cte).filter(your_window_function='something')
Which translates roughly to:
WITH cte as (
SELECT *, WINDOW(...) as your_window_function
FROM yourmodel
)
SELECT *
FROM cte
WHERE cte.your_window_function = 'something'
与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…