Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Test usage of from_queryset manager as reverse manager #2295

Merged
merged 1 commit into from
Jul 30, 2024
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
22 changes: 22 additions & 0 deletions tests/typecheck/managers/querysets/test_from_queryset.yml
Original file line number Diff line number Diff line change
Expand Up @@ -946,3 +946,25 @@
main:12: error: Argument 1 to "from_queryset" of "BaseManager" has incompatible type "<typing special form>"; expected "Type[QuerySet[Model, Model]]" [arg-type]
main:17: note: Revealed type is "Type[django.db.models.manager.Manager[django.db.models.base.Model]]"
main:17: error: Argument 1 to "from_queryset" of "BaseManager" has incompatible type "Type[NonQSGeneric[Any]]"; expected "Type[QuerySet[Model, Model]]" [arg-type]

- case: test_reverse_manager_with_foreign_key
main: |
from myapp.models import B
reveal_type(B().a_set.filter(field="something")) # N: Revealed type is "myapp.models.QS"
installed_apps:
- myapp
files:
- path: myapp/__init__.py
- path: myapp/models.py
content: |
from django.db import models

class B(models.Model): ...

class QS(models.QuerySet["A"]): ...

Manager = models.Manager.from_queryset(QS)
class A(models.Model):
field = models.CharField()
b = models.ForeignKey(B, on_delete=models.CASCADE)
objects = Manager()
Loading