0

I have the following queryset

qs = Model.objects.\
    filter(user_id=request.user.pk).\
    only('item_id', 'action', 'performed_at').\
    order_by().\
    order_by('performed_at')

This queryset will fetch some duplicate Models but with different performed_at and with same item_id. What I want is to keep most recent occurrence by item_id keeping the order_by and without evaluating the queryset.

marc_s
  • 732,580
  • 175
  • 1,330
  • 1,459
dios231
  • 714
  • 1
  • 9
  • 21
  • you mean something like a SQL `GROUP BY item_id` clause? In that case look at [this answer](https://stackoverflow.com/a/629691/9225671) – Ralf Jul 16 '19 at 14:25
  • I think yes. if these means that the Queryset will keep the order_by – dios231 Jul 16 '19 at 14:30

0 Answers0