Clone the queryset using GroupByQuerySet.

        :param fields:
        :return:
509357
def group_by(self, *fields):
        
        fields = self._expand_group_by_fields(self.model, fields)
        return self._clone(klass=GroupByQuerySet, setup=True, _fields=fields)
55795
def _set_queryset(self, queryset):
        
        self.fields[0].queryset = self.widget.queryset = queryset
        self.widget.choices = self.fields[0].choices
690218
def get_fields_by_class(cls, field_class):
        

        ret = []

        for key, val in getattr(cls, '_fields').items():
            if isinstance(val, field_class):
                ret.append(key)
        return ret
360316
def query_all(self):
        
        if DJANGO_20_PLUS:
            obj = self._clone()
        else:
            obj = self._clone(klass=SalesforceQuerySet)  # pylint: disable=unexpected-keyword-arg
        obj.query.set_query_all()
        return obj
910704
def values_list(self, *fields, **kwargs):
        
        flat = kwargs.pop('flat', False)
        if kwargs:
            raise TypeError('Unexpected keyword arguments to values_list: %s'
                            % (kwargs.keys(),))
        if flat and len(fields) > 1:
            raise TypeError("'flat' is not valid when values_list is called with more than one field.")
        clone = self.only(fields)
        clone._values_list = True
        clone._flat_values_list = flat
        return clone
84729
def using_db(self, _db: BaseDBAsyncClient) -> "QuerySet":
        
        queryset = self._clone()
        queryset._db = _db
        return queryset
817187
def clone_data( self, source ):
        
        klass = self.__class__
        assert isinstance( source, klass )

        for name in klass._fields:
            self._field_data[name] = getattr( source, name )
662651
def get_db_distinct(queryset, field, func, **params):
    
    while True:
        try:
            value = func(**params)
            queryset.get(**{field: value})
        except ObjectDoesNotExist:
            break
    return value
456611
def groupby_field(records, field_name, skip_none=True):
    
    return apply_groupby(
        records,
        lambda obj: getattr(obj, field_name),
        skip_none=skip_none)
1176437
def fieldgetter(*fieldspecs):
    
    pattern = r'(?P<field>[^.]+)(.(?P<subfield>[^.]+))?'

    def fields(record):
        for s in fieldspecs:
            match = re.match(pattern, s)
            if not match:
                continue
            grp = match.groupdict()
            for field in record.get_fields(grp['field']):
                if grp['subfield']:
                    for value in field.get_subfields(grp['subfield']):
                        yield field, value
                else:
                    if int(grp['field']) < 10:
                        yield field, field.value()
                    else:
                        for value in field.subfields[1::2]:
                            yield field, value
    fields.__doc__ = 'returns a field generator over %s' % (
        ', '.join(fieldspecs))
    return fields
325965
def set_fields(self, **fields):
        
        for field_name, value in iteritems(fields):
            field = getattr(self, field_name)
            field.proxy_set(value)
208872
def group_by(self, key, field=lambda x: x.xfer):
        
        return Transactions([t for t in self.trans if field(t) == key])
700781
def get_queryset(self, *args, **kwargs):
        
        qs = super(AutoPrefetchMixin, self).get_queryset(*args, **kwargs)
        included_resources = get_included_resources(self.request)

        for included in included_resources:
            included_model = None
            levels = included.split('.')
            level_model = qs.model
            for level in levels:
                if not hasattr(level_model, level):
                    break
                field = getattr(level_model, level)
                field_class = field.__class__

                is_forward_relation = (
                    issubclass(field_class, ForwardManyToOneDescriptor) or
                    issubclass(field_class, ManyToManyDescriptor)
                )
                is_reverse_relation = (
                    issubclass(field_class, ReverseManyToOneDescriptor) or
                    issubclass(field_class, ReverseOneToOneDescriptor)
                )
                if not (is_forward_relation or is_reverse_relation):
                    break

                if level == levels[-1]:
                    included_model = field
                else:

                    if issubclass(field_class, ReverseOneToOneDescriptor):
                        model_field = field.related.field
                    else:
                        model_field = field.field

                    if is_forward_relation:
                        level_model = model_field.related_model
                    else:
                        level_model = model_field.model

            if included_model is not None:
                qs = qs.prefetch_related(included.replace('.', '__'))

        return qs
1680
def filter_by(self, **kwargs):
        
        query = self._copy()
        for field, value in kwargs.items():
            query.domain.append(
                (field, '=', value)
            )
        return query
498395
def serialize(self, queryset, **options):
        
        self.options = options

        self.stream = options.get("stream", StringIO())
        self.primary_key = options.get("primary_key", None)
        self.properties = options.get("properties")
        self.geometry_field = options.get("geometry_field", "geom")
        self.use_natural_keys = options.get("use_natural_keys", False)
        self.bbox = options.get("bbox", None)
        self.bbox_auto = options.get("bbox_auto", None)
        self.srid = options.get("srid", GEOJSON_DEFAULT_SRID)
        self.crs = options.get("crs", True)

        self.start_serialization()

        if ValuesQuerySet is not None and isinstance(queryset, ValuesQuerySet):
            self.serialize_values_queryset(queryset)

        elif isinstance(queryset, list):
            self.serialize_object_list(queryset)

        elif isinstance(queryset, QuerySet):
            self.serialize_queryset(queryset)

        self.end_serialization()
        return self.getvalue()
1093492
def _get_data(self, fields=None, compare=True):
        
        fields = fields or []
        if self._key is None or self._key == '' or self._key == 0:
            d = {}
            for k, v in self.properties.items():
                #test fields
                if fields and k not in fields:
                    continue
#                if not isinstance(v, ManyToMany):
                if v.property_type == 'compound':
                    continue
                if v.sequence:
                    continue
                if not isinstance(v, ManyToMany):
                    x = v.get_value_for_datastore(self)
                    if isinstance(x, Model):
                        x = x._key
                    elif x is None or (k==self._primary_field and not x):
                        if isinstance(v, DateTimeProperty) and v.auto_now_add:
                            x = v.now()
                        elif (v.auto_add or (not v.auto and not v.auto_add)):
                            x = v.default_value()
                else:
                    x = v.get_value_for_datastore(self, cached=True)
                if x is not None and not x is Lazy:
                    d[k] = x
        else:
            d = {}
            d[self._primary_field] = self._key
            for k, v in self.properties.items():
                if fields and k not in fields:
                    continue
                if v.property_type == 'compound':
                    continue
                t = self._old_values.get(k, None)
                if not isinstance(v, ManyToMany):
                    x = v.get_value_for_datastore(self)
                    if isinstance(x, Model):
                        x = x._key
                else:
                    x = v.get_value_for_datastore(self, cached=True)
                if not x is Lazy:
                    if (compare and t != self.field_str(x)) or not compare:
                        d[k] = x
        
        return d
484215
def filter(other_query)
      query  = self.query
      fields = query.fields.to_set
      unique = other_query.unique?

      # TODO: push this into a Query#subset? method
      if other_query.links.empty?                 &&
        (unique || (!unique && !query.unique?))   &&
        !other_query.reload?                      &&
        !other_query.raw?                         &&
        other_query.fields.to_set.subset?(fields) &&
        other_query.condition_properties.subset?(fields)
      then
        other_query.filter_records(to_a.dup)
      end
    end