MCPcopy
hub / github.com/tortoise/tortoise-orm / values

Method values

tortoise/queryset.py:689–742  ·  view source on GitHub ↗

Make QuerySet return dicts instead of objects. If called after `.get()`, `.get_or_none()` or `.first()`, returns a dict instead of an object. You can specify which fields to include by: - Passing field names as positional arguments - Using kwargs in the for

(self, *args: str, **kwargs: str)

Source from the content-addressed store, hash-verified

687 )
688
689 def values(self, *args: str, **kwargs: str) -> ValuesQuery[Literal[False]]:
690 """
691 Make QuerySet return dicts instead of objects.
692
693 If called after `.get()`, `.get_or_none()` or `.first()`, returns a dict instead of an object.
694
695 You can specify which fields to include by:
696 - Passing field names as positional arguments
697 - Using kwargs in the format `field_name='name_in_dict'` to customize the keys in the resulting dict
698
699 If no arguments are passed, it will default to a dict containing all fields.
700
701 :raises FieldError: If duplicate key has been provided.
702 """
703 if self._fields_for_select:
704 raise ValueError(".values() cannot be used with .only()")
705
706 if args or kwargs:
707 fields_for_select: dict[str, str] = {}
708 for field in args:
709 if field in fields_for_select:
710 raise FieldError(f"Duplicate key {field}")
711 fields_for_select[field] = field
712
713 for return_as, field in kwargs.items():
714 if return_as in fields_for_select:
715 raise FieldError(f"Duplicate key {return_as}")
716 fields_for_select[return_as] = field
717 else:
718 _fields = [
719 field
720 for field in self.model._meta.fields_map.keys()
721 if field in self.model._meta.fields_db_projection.keys()
722 ] + list(self._annotations.keys())
723
724 fields_for_select = {field: field for field in _fields}
725
726 return ValuesQuery(
727 db=self._db,
728 model=self.model,
729 q_objects=self._q_objects,
730 single=self._single,
731 raise_does_not_exist=self._raise_does_not_exist,
732 fields_for_select=fields_for_select,
733 distinct=self._distinct,
734 limit=self._limit,
735 offset=self._offset,
736 orderings=self._orderings,
737 annotations=self._annotations,
738 custom_filters=self._custom_filters,
739 group_bys=self._group_bys,
740 force_indexes=self._force_indexes,
741 use_indexes=self._use_indexes,
742 )
743
744 def delete(self) -> DeleteQuery:
745 """

Callers 2

_resolve_annotateMethod · 0.45
_executeMethod · 0.45

Calls 4

FieldErrorClass · 0.90
ValuesQueryClass · 0.85
itemsMethod · 0.80
keysMethod · 0.80

Tested by

no test coverage detected