|from functools import reduce|
|results = qs.model.objects.raw(sql, sql_params)|
|obj_ranks = (obj.id for obj in results)|
|return_objs = |
|# inject rank|
|for obj_id, objs.items():|
|if len(return_objs) > 0:|
|qs = reduce(operator.or_, return_objs)|
|qs = qs.model.objects.none()|
@DiegoMagg, while yours is likely more efficient, it loses the main benefit of the gist: To keep the new QuerySet if the same ordering as the RawQuerySet.
If order doesn't matter, then yours is the better alternative, but if you set a specific ordering in the raw query, then the gist's approach (or something like it) is the way to go.
This does not work for me