1👍
✅
Try this:
EntryRank.objects.all().exclude(user__user__id = user_id).order_by('-rank', 'user__id')
In this case you filter some users with exclude
clause and order the result by EntryRank.rank
You can increase the complexity of exclude clause like:
user__user__user__username__in = [auth_user.id1, auth_user.id2,.. ]
Once you iterate the results you can get Entry
and SomeUsers
references from your EntryRank
object
for entry_rank in EntryRank.objects.all().exclude(user__user__id = user_id).order_by('-rank', 'user__id'):
entry_rank.value #rank
entry_rank.user #SomeUser
entry_rank.entry #Entry
Source:stackexchange.com