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

Method from_queryset

tortoise/contrib/pydantic/base.py:114–124  ·  view source on GitHub ↗

Returns a serializable pydantic model instance that contains a list of models, from the provided queryset. This will prefetch all the relations automatically. :param queryset: a queryset on the model this PydanticModel is based on.

(cls, queryset: QuerySet)

Source from the content-addressed store, hash-verified

112
113 @classmethod
114 async def from_queryset(cls, queryset: QuerySet) -> list[Self]:
115 """
116 Returns a serializable pydantic model instance that contains a list of models,
117 from the provided queryset.
118
119 This will prefetch all the relations automatically.
120
121 :param queryset: a queryset on the model this PydanticModel is based on.
122 """
123 fetch_fields = _get_fetch_fields(cls, cls.model_config["orig_model"]) # type: ignore
124 return [cls.model_validate(e) for e in await queryset.prefetch_related(*fetch_fields)]
125
126
127class PydanticListModel(RootModel):

Callers 5

test_eventlistFunction · 0.45
users_listFunction · 0.45
runFunction · 0.45
runFunction · 0.45
get_usersFunction · 0.45

Calls 2

_get_fetch_fieldsFunction · 0.85
prefetch_relatedMethod · 0.45

Tested by 1

test_eventlistFunction · 0.36