def order_by(self, *args): args = list(args) joins_needed = [] for idx, arg in enumerate(args): q = self if not isinstance(arg, basestring): continue if arg[0] in '+-': desc = arg[0] == '-' arg = arg[1:] else: desc = False q = self column = None for token in arg.split('__'): column = _entity_descriptor(q._joinpoint_zero(), token) if column.impl.uses_objects: q = q.join(column) joins_needed.append(column) column = None if column is None: raise ValueError('Tried to order by table, column expected') if desc: column = column.desc() args[idx] = column q = super(DjangoQueryMixin, self).order_by(*args) for join in joins_needed: q = q.join(join) return q
def _filter_or_exclude(self, negate, kwargs): q = self negate_if = lambda expr: expr if not negate else ~expr column = None for arg, value in kwargs.iteritems(): for token in arg.split('__'): if column is None: column = _entity_descriptor(q._joinpoint_zero(), token) if column.impl.uses_objects: q = q.join(column) column = None elif token in self._underscore_operators: op = self._underscore_operators[token] q = q.filter(negate_if(op(column, *to_list(value)))) column = None else: raise ValueError('No idea what to do with %r' % token) if column is not None: q = q.filter(negate_if(column == value)) column = None q = q.reset_joinpoint() return q