mirror of
https://github.com/davidhalter/django-stubs.git
synced 2025-12-13 23:41:55 +08:00
Fix RelatedManager not callable (#1191)
* Add failing test * Add call annotation
This commit is contained in:
@@ -172,6 +172,7 @@ class RelatedManager(Manager[_T]):
|
|||||||
self, objs: Union[QuerySet[_T], Iterable[Union[_T, int]]], *, bulk: bool = ..., clear: bool = ...
|
self, objs: Union[QuerySet[_T], Iterable[Union[_T, int]]], *, bulk: bool = ..., clear: bool = ...
|
||||||
) -> None: ...
|
) -> None: ...
|
||||||
def clear(self) -> None: ...
|
def clear(self) -> None: ...
|
||||||
|
def __call__(self, *, manager: str) -> RelatedManager[_T]: ...
|
||||||
|
|
||||||
class ManagerDescriptor:
|
class ManagerDescriptor:
|
||||||
manager: BaseManager = ...
|
manager: BaseManager = ...
|
||||||
|
|||||||
@@ -908,3 +908,23 @@
|
|||||||
from django.db import models
|
from django.db import models
|
||||||
T = TypeVar("T", bound=models.Model)
|
T = TypeVar("T", bound=models.Model)
|
||||||
ManyToManyFieldAlias = Union["models.ManyToManyField[Sequence[T], models.manager.RelatedManager[T]]"]
|
ManyToManyFieldAlias = Union["models.ManyToManyField[Sequence[T], models.manager.RelatedManager[T]]"]
|
||||||
|
|
||||||
|
- case: callable_reverse_manager
|
||||||
|
main: |
|
||||||
|
from myapp.models import SalesMan
|
||||||
|
sales_man = SalesMan()
|
||||||
|
reveal_type(sales_man.client) # N: Revealed type is "django.db.models.manager.RelatedManager[myapp.models.CustomUser]"
|
||||||
|
reveal_type(sales_man.client(manager="staffs")) # N: Revealed type is "django.db.models.manager.RelatedManager[myapp.models.CustomUser]"
|
||||||
|
installed_apps:
|
||||||
|
- myapp
|
||||||
|
files:
|
||||||
|
- path: myapp/__init__.py
|
||||||
|
- path: myapp/models.py
|
||||||
|
content: |
|
||||||
|
from django.db import models
|
||||||
|
|
||||||
|
class CustomUser(models.Model):
|
||||||
|
staffs = models.Manager()
|
||||||
|
|
||||||
|
class SalesMan(models.Model):
|
||||||
|
client = models.ManyToManyField(CustomUser)
|
||||||
|
|||||||
Reference in New Issue
Block a user