'Given a dictionary of options, apply some ORM-level sorting to the
provided ``QuerySet``.
Looks for the ``order_by`` key and handles either ascending (just the
field name) or descending (the field name with a ``-`` in front).
The field name should be the resource field, **NOT** model field.'

def apply_sorting(self, obj_list, options=None):

    if (options is None):
        options = {}
    parameter_name = u'order_by'
    if (u'order_by' not in options):
        if (u'sort_by' not in options):
            return obj_list
        else:
            warnings.warn(u"'sort_by'    is    a    deprecated    parameter.    Please    use    'order_by'    instead.")
            parameter_name = u'sort_by'
    order_by_args = []
    if hasattr(options, u'getlist'):
        order_bits = options.getlist(parameter_name)
    else:
        order_bits = options.get(parameter_name)
        if (not isinstance(order_bits, (list, tuple))):
            order_bits = [order_bits]
    for order_by in order_bits:
        order_by_bits = order_by.split(LOOKUP_SEP)
        field_name = order_by_bits[0]
        order = u''
        if order_by_bits[0].startswith(u'-'):
            field_name = order_by_bits[0][1:]
            order = u'-'
        if (field_name not in self.fields):
            raise InvalidSortError((u"No    matching    '%s'    field    for    ordering    on." % field_name))
        if (field_name not in self._meta.ordering):
            raise InvalidSortError((u"The    '%s'    field    does    not    allow    ordering." % field_name))
        if (self.fields[field_name].attribute is None):
            raise InvalidSortError((u"The    '%s'    field    has    no    'attribute'    for    ordering    with." % field_name))
        order_by_args.append((u'%s%s' % (order, LOOKUP_SEP.join(([self.fields[field_name].attribute] + order_by_bits[1:])))))
    return obj_list.order_by(*order_by_args)
