Basically, I want to do this but with django 2.0.
If I try:
Purchases.objects.filter(.....).annotate(my_max=Window(
expression=Max('field_of_interest'),
partition_by=F('customer')
)
)
I get back all the rows but with the my_max
property added to each record.
If you are using PostgreSQL:
UPDATE: Window expressions are not allowed in filter, so following methods does not work. Please refer to this answer for up-to-date solution
or with
Window
expressionbut latter can yield multiple rows per customer if they have the same
field_of_interest
Another
Window
, with single row per customer