|
| 1 | +- case: test_related_name_custom_manager |
| 2 | + main: | |
| 3 | + from app1.models import Model1 |
| 4 | + from app2.models import Model2 |
| 5 | +
|
| 6 | + reveal_type(Model1().test) # N: Revealed type is "app3.models.Model3_RelatedManager" |
| 7 | + reveal_type(Model2().test) # N: Revealed type is "app3.models.Model3_RelatedManager" |
| 8 | + reveal_type(Model1().test2) # N: Revealed type is "app3.models.Model4_RelatedManager" |
| 9 | + reveal_type(Model2().test2) # N: Revealed type is "app3.models.Model4_RelatedManager" |
| 10 | + installed_apps: |
| 11 | + - base |
| 12 | + - users |
| 13 | + - app1 |
| 14 | + - app2 |
| 15 | + - app3 |
| 16 | + files: |
| 17 | + - path: base/__init__.py |
| 18 | + - path: base/models.py |
| 19 | + content: | |
| 20 | + from django.db import models |
| 21 | + class OwnedModel(models.Model): |
| 22 | + owner = models.ForeignKey("users.User", on_delete=models.CASCADE) |
| 23 | +
|
| 24 | + class Meta: |
| 25 | + abstract = True |
| 26 | +
|
| 27 | + - path: users/__init__.py |
| 28 | + - path: users/models.py |
| 29 | + content: | |
| 30 | + from django.db import models |
| 31 | + class User(models.Model): |
| 32 | + pass |
| 33 | +
|
| 34 | + - path: app1/__init__.py |
| 35 | + - path: app1/models.py |
| 36 | + content: | |
| 37 | + from django.db import models |
| 38 | + from base.models import OwnedModel |
| 39 | + from typing import TYPE_CHECKING |
| 40 | + if TYPE_CHECKING: |
| 41 | + from app3.models import Model3 |
| 42 | +
|
| 43 | + class CustomQuerySet(models.QuerySet): |
| 44 | + pass |
| 45 | +
|
| 46 | + Model1Manager = models.Manager.from_queryset(CustomQuerySet) |
| 47 | + class Model1(OwnedModel): |
| 48 | + objects = Model1Manager() |
| 49 | +
|
| 50 | + - path: app2/__init__.py |
| 51 | + - path: app2/models.py |
| 52 | + content: | |
| 53 | + from django.db import models |
| 54 | + from base.models import OwnedModel |
| 55 | + from typing import TYPE_CHECKING |
| 56 | + if TYPE_CHECKING: |
| 57 | + from app3.models import Model3 |
| 58 | +
|
| 59 | + class CustomQuerySet(models.QuerySet): |
| 60 | + pass |
| 61 | +
|
| 62 | + Model2Manager = models.Manager.from_queryset(CustomQuerySet) |
| 63 | + class Model2(OwnedModel): |
| 64 | + objects = Model2Manager() |
| 65 | +
|
| 66 | + - path: app3/__init__.py |
| 67 | + - path: app3/models.py |
| 68 | + content: | |
| 69 | + from django.db import models |
| 70 | + from app1.models import Model1 |
| 71 | + from app2.models import Model2 |
| 72 | + from base.models import OwnedModel |
| 73 | +
|
| 74 | + class CustomQuerySet(models.QuerySet): |
| 75 | + pass |
| 76 | +
|
| 77 | + Model3Manager = models.Manager.from_queryset(CustomQuerySet) |
| 78 | + class Model3(OwnedModel): |
| 79 | + a = models.ForeignKey(Model1, related_name="test", on_delete=models.CASCADE) |
| 80 | + b = models.ForeignKey(Model2, related_name="test", on_delete=models.CASCADE) |
| 81 | +
|
| 82 | + objects = Model3Manager() |
| 83 | +
|
| 84 | + Model4Manager = models.Manager.from_queryset(CustomQuerySet) |
| 85 | + class Model4(OwnedModel): |
| 86 | + a = models.ForeignKey(Model1, related_name="test2", on_delete=models.CASCADE) |
| 87 | + b = models.ForeignKey(Model2, related_name="test2", on_delete=models.CASCADE) |
| 88 | +
|
| 89 | + objects = Model4Manager() |
0 commit comments