On 20 kesä, 20:37, Peter Ung <ung.pe...@gmail.com> wrote: > Thanks Chris for your response; however, its not the solution I'm looking > for. I need the ranking to go in sequential order - the solution you > provided will just make my points, or scores in your example, the rank. I > need, for example, the person with the highest number of scores/points with > the rank 1 associated their record in the queryset. Then rank 2 for the > next person with highest score/points. etc > > Any ideas on how to achieve that? Only solution I'm seeing at the moment is > to add rank to the model and update rank every time a user calls the > leaderboard - which would be expensive and slow wouldn't it?
Django's ORM doesn't support windowing functions. The problem isn't adding the windowing function (rank() in this case) to the SELECT clause. You can do this with .extra() currently. The real problem is that to filter on the result, you need to push the query down into inner subquery, then do the filter in the outer query. This isn't supported. So, it seems this is not doable without using raw SQL. - Anssi -- You received this message because you are subscribed to the Google Groups "Django users" group. To post to this group, send email to django-users@googlegroups.com. To unsubscribe from this group, send email to django-users+unsubscr...@googlegroups.com. For more options, visit this group at http://groups.google.com/group/django-users?hl=en.