mirror of
https://github.com/HackSoftware/Django-Styleguide.git
synced 2025-02-12 01:20:51 +03:00
Add types.py
with QuerySetType
implementation
This commit is contained in:
parent
7f2d665292
commit
7b8155e7b1
|
@ -695,6 +695,8 @@ class Payment(models.Model):
|
||||||
|
|
||||||
**This is our selector:**
|
**This is our selector:**
|
||||||
|
|
||||||
|
For implementation of `QuerySetType`, check `types.py`.
|
||||||
|
|
||||||
```python
|
```python
|
||||||
from django.contrib.auth.models import User
|
from django.contrib.auth.models import User
|
||||||
|
|
||||||
|
|
49
types.py
Normal file
49
types.py
Normal file
|
@ -0,0 +1,49 @@
|
||||||
|
from typing import Generic, Iterator, Any, TypeVar, Optional, Dict, Tuple
|
||||||
|
from collections import Iterable
|
||||||
|
|
||||||
|
|
||||||
|
DjangoModel = TypeVar('DjangoModel')
|
||||||
|
|
||||||
|
|
||||||
|
class QuerySetType(Generic[DjangoModel], extra=Iterable):
|
||||||
|
"""
|
||||||
|
This type represents django.db.models.QuerySet interface.
|
||||||
|
|
||||||
|
Defined Types:
|
||||||
|
DjangoModel - model instance
|
||||||
|
QuerysetType[DjangoModel] - Queryset of DjangoModel instances
|
||||||
|
Iterator[DjangoModel] - Iterator of DjangoModel instances
|
||||||
|
"""
|
||||||
|
def __iter__(self) -> Iterator[DjangoModel]: ...
|
||||||
|
|
||||||
|
def all(self) -> 'QuerySetType[DjangoModel]': ...
|
||||||
|
|
||||||
|
def order_by(self, *args: Any) -> 'QuerySetType[DjangoModel]': ...
|
||||||
|
|
||||||
|
def count(self) -> int: ...
|
||||||
|
|
||||||
|
def filter(self, **kwargs: Any) -> 'QuerySetType[DjangoModel]': ...
|
||||||
|
|
||||||
|
def exclude(self, **kwargs: Any) -> 'QuerySetType[DjangoModel]': ...
|
||||||
|
|
||||||
|
def get(self, **kwargs: Any) -> DjangoModel: ...
|
||||||
|
|
||||||
|
def annotate(self, **kwargs: Any) -> 'QuerySetType[DjangoModel]': ...
|
||||||
|
|
||||||
|
def first(self) -> Optional[DjangoModel]: ...
|
||||||
|
|
||||||
|
def update(self, **kwargs: Any) -> DjangoModel: ...
|
||||||
|
|
||||||
|
def delete(self, **kwargs: Any) -> Tuple[int, Dict[str, int]]: ...
|
||||||
|
|
||||||
|
def last(self) -> Optional[DjangoModel]: ...
|
||||||
|
|
||||||
|
def exists(self) -> bool: ...
|
||||||
|
|
||||||
|
def values(self, *args: Any) -> 'QuerySetType[DjangoModel]': ...
|
||||||
|
|
||||||
|
def values_list(self, *args: Any) -> 'QuerySetType[DjangoModel]': ...
|
||||||
|
|
||||||
|
def __getitem__(self, index: int) -> DjangoModel: ...
|
||||||
|
|
||||||
|
def __len__(self) -> int: ...
|
Loading…
Reference in New Issue
Block a user