since you only care about  the position, to make the query less horrible I suggest something like this:
- adding a qs = qs.values_list('user_id', flat=True)
- using d.get('user_id')

(My idea is to only fetch the user_ids, no other fields, and not building useless UserProfile instances)