def _comparator_func(self, obj): (value, ) = cmp(self.attr)(obj) if self.verb: return self.apply_verb(value) else: return value == self.value
def distinct(self, *attrs): if not attrs: attrs = self._attrs - {'created', 'updated'} meta = [(cmp(*attrs)(obj), obj) for obj in self.reverse()] return type(self)(OrderedDict(meta).values())
def values(self, *attrs): if not attrs: attrs = self._attrs return type(self)( (dict(zip(attrs, obj)) for obj in map(cmp(*attrs), self)), model=self.model)
def order_by(self, *fields: Fields): if not fields: raise AttributeError return type(self)( sorted(self, key=cmp(*fields)), model=self.model )
def values(self, *fields: Fields) -> 'QuerySet': if not fields: fields = self._attrs return type(self)( ( dict(zip(fields, obj)) for obj in map(cmp(*fields), self) ), model=self.model )
def values_list(self, *attrs, flat=False): # TODO: Allow order_by on values_list if not attrs: attrs = self._attrs if len(attrs) > 1 and flat: raise TypeError( '/flat/ is not valid when values_list is called with more than ' 'one field.') return type(self)((flatmap if flat else map)(cmp(*attrs), self))
def distinct(self, *fields: Fields) -> 'QuerySet': if not fields: fields = self._attrs - {'created', 'updated'} meta = [ (cmp(*fields)(obj), obj) for obj in self.reverse() ] return type(self)( OrderedDict(meta).values(), model=self.model ).reverse()
def values_list(self, *fields: Fields, flat: bool=False) -> 'QuerySet': # TODO: Allow order_by on values_list if not fields: fields = self._attrs if len(fields) > 1 and flat: raise TypeError( '/flat/ is not valid when values_list is called with more than ' 'one field.' ) return type(self)( (flatmap if flat else map)(cmp(*fields), self), model=self.model )
def order_by(self, *attrs): if not attrs: raise AttributeError return type(self)(sorted(self, key=cmp(*attrs)))