this is my query which gives me the ranking of all user:
rank = Wallet.objects.filter(type=0, space_id=space.id).annotate(
rank=Window(
expression=DenseRank(),
order_by=F('point_amount').desc(),
)
).order_by('rank').values("user__id","user__username","rank")
but how can i get rank of specific user in this query?(i don’t want to handle this whit python)
i already try this:
rank = Wallet.objects.filter(type=0, space_id=space.id, user_id=user.id).annotate(
rank=Window(
expression=DenseRank(),
order_by=F('point_amount').desc(),
)
).order_by('rank').values("user__id","user__username","rank")
but it gives me rank 1 which is not correct
note:
this raw query gives me the right answer but i don’t konw how to convert this in to django orm query
query = f'''
SELECT
FIND_IN_SET(
`transaction_wallet`.`point_amount`,
(
SELECT
GROUP_CONCAT(`transaction_wallet`.`point_amount` ORDER BY `transaction_wallet`.`point_amount` DESC)
FROM `transaction_wallet`
WHERE `transaction_wallet`.`type` = 0 AND `transaction_wallet`.`space_id` = {space.id}
)
) AS `rank`
FROM
`transaction_wallet`
WHERE
`transaction_wallet`.`type` = 0 AND `transaction_wallet`.`space_id` = {space.id} AND `transaction_wallet`.`user_id` = {self.id};
'''