'Returns the proper model field name corresponding to the given
field_name to use for ordering. field_name may either be the name of a
proper model field or the name of a method (on the admin or model) or a
callable with the \'admin_order_field\' attribute. Returns None if no
proper model field name can be matched.'

def get_ordering_field(self, field_name):

    try:
        field = self.lookup_opts.get_field(field_name)
        return field.name
    except models.FieldDoesNotExist:
        if callable(field_name):
            attr = field_name
        elif hasattr(self.model_admin, field_name):
            attr = getattr(self.model_admin, field_name)
        else:
            attr = getattr(self.model, field_name)
        return getattr(attr, 'admin_order_field', None)
