'Column sorting logic based on request GET parameters.
Deals with objects with joins on the Addon (e.g. RereviewQueue,
Version). Returns qs of apps.'

def _do_sort_queue_obj(self, qs, date_sort):

    (sort_type, order) = clean_sort_param(self.request, date_sort=date_sort)
    sort_str = sort_type
    if (sort_type not in [date_sort, 'name']):
        sort_str = ('addon__' + sort_type)
    order_by = (('-' if (order == 'desc') else '') + sort_str)
    if (sort_type == 'name'):
        return order_by_translation(Webapp.objects.filter(id__in=qs.values_list('addon', flat=True)), order_by)
    sorted_app_ids = qs.order_by('-addon__priority_review', order_by).values_list('addon', flat=True)
    qs = Webapp.objects.filter(id__in=sorted_app_ids)
    return manual_order(qs, sorted_app_ids, 'addons.id')
