def sort_by_attribute(self, qs, name):
        """
        A wrapper around standard order_by() method. Allows to sort by both normal
        fields and EAV attributes without thinking about implementation details.
        Usage::

            qs = sort_by_attributes(qs, 'price', 'colour')

        ...where `price` is a FloatField, and `colour` is the name of an EAV attribute
        represented by Schema and Attr models.
        """
        fields   = self.get_queryset().model._meta.get_all_field_names()
        schemata = self.sortable_names
        direction = '-' if self.data.get('order_desc') else ''
        if name in fields:
            return qs.order_by('%s%s' % (direction, name))
        elif name in schemata:
            schema = self.get_schema(name)
            value_lookup = 'attrs__value_%s' % schema.datatype
            order_lookup = '%s%s' % (direction, value_lookup)
            return qs.filter(attrs__schema__name=name).order_by(order_lookup)
        else:
            raise NameError('Cannot order items by attributes: unknown '
                            'attribute "%s". Available fields: %s. '
                            'Available schemata: %s.' % (name,
                            ', '.join(fields), ', '.join(schemata)))