mirror of
https://github.com/davidhalter/django-stubs.git
synced 2025-12-08 04:54:48 +08:00
Add annotations for Prefetch, prefetch_related_objects.
This commit is contained in:
@@ -122,3 +122,25 @@ class RawQuerySet(Iterable[_T], Sized):
|
||||
def prefetch_related(self, *lookups: Any) -> RawQuerySet[_T]: ...
|
||||
def resolve_model_init_order(self) -> Tuple[List[str], List[int], List[Tuple[str, int]]]: ...
|
||||
def using(self, alias: Optional[str]) -> RawQuerySet[_T]: ...
|
||||
|
||||
class Prefetch(object):
|
||||
def __init__(self, lookup, queryset=None, to_attr=None):
|
||||
# `prefetch_through` is the path we traverse to perform the prefetch.
|
||||
self.prefetch_through = lookup
|
||||
# `prefetch_to` is the path to the attribute that stores the result.
|
||||
self.prefetch_to = lookup
|
||||
if queryset is not None and not issubclass(queryset._iterable_class, ModelIterable):
|
||||
raise ValueError('Prefetch querysets cannot use values().')
|
||||
if to_attr:
|
||||
self.prefetch_to = LOOKUP_SEP.join(lookup.split(LOOKUP_SEP)[:-1] + [to_attr])
|
||||
|
||||
self.queryset = queryset
|
||||
self.to_attr = to_attr
|
||||
|
||||
def __getstate__(self) -> Dict[str, Any]: ...
|
||||
def add_prefix(self, prefix: str) -> None: ...
|
||||
def get_current_prefetch_to(self, level: int) -> str: ...
|
||||
def get_current_to_attr(self, level: int) -> Tuple[str,str]: ...
|
||||
def get_current_queryset(self, level) -> Optional[QuerySet]: ...
|
||||
|
||||
def prefetch_related_objects(model_instances: Iterable[_T], *related_lookups: str) -> None: ...
|
||||
|
||||
Reference in New Issue
Block a user