|
1502 | 1502 | - case: test_reverse_m2m_relation_checks_other_model |
1503 | 1503 | main: | |
1504 | 1504 | from myapp.models import Author |
| 1505 | + # With builtin manager/queryset |
1505 | 1506 | Author().book_set.filter(featured=True) |
1506 | 1507 | Author().book_set.filter(xyz=True) # E: Cannot resolve keyword 'xyz' into field. Choices are: authors, featured, id [misc] |
| 1508 | + reveal_type(Author().book_set.values_list("featured")) # N: Revealed type is "django.db.models.query.QuerySet[myapp.models.Book, Tuple[builtins.bool]]" |
| 1509 | + Author().book_set.values_list("xyz") # E: Cannot resolve keyword 'xyz' into field. Choices are: authors, featured, id [misc] |
| 1510 | + reveal_type(Author().book_set.values("featured")) # N: Revealed type is "django.db.models.query.QuerySet[myapp.models.Book, TypedDict({'featured': builtins.bool})]" |
| 1511 | + Author().book_set.values("xyz") # E: Cannot resolve keyword 'xyz' into field. Choices are: authors, featured, id [misc] |
| 1512 | + reveal_type(Author().book_set.filter(featured=True).values_list("featured")) # N: Revealed type is "django.db.models.query.QuerySet[myapp.models.Book, Tuple[builtins.bool]]" |
| 1513 | + Author().book_set.filter(featured=True).values_list("xyz") # E: Cannot resolve keyword 'xyz' into field. Choices are: authors, featured, id [misc] |
| 1514 | + reveal_type(Author().book_set.filter(featured=True).values("featured")) # N: Revealed type is "django.db.models.query.QuerySet[myapp.models.Book, TypedDict({'featured': builtins.bool})]" |
| 1515 | + Author().book_set.filter(featured=True).values("xyz") # E: Cannot resolve keyword 'xyz' into field. Choices are: authors, featured, id [misc] |
| 1516 | +
|
| 1517 | + # With a custom manager/queryset |
| 1518 | + Author().other_set.filter(featured=True) |
| 1519 | + Author().other_set.filter(xyz=True) # E: Cannot resolve keyword 'xyz' into field. Choices are: authors, featured, id [misc] |
| 1520 | + reveal_type(Author().other_set.values_list("featured")) # N: Revealed type is "django.db.models.query.QuerySet[myapp.models.Other, Tuple[builtins.bool]]" |
| 1521 | + Author().other_set.values_list("xyz") # E: Cannot resolve keyword 'xyz' into field. Choices are: authors, featured, id [misc] |
| 1522 | + reveal_type(Author().other_set.values("featured")) # N: Revealed type is "django.db.models.query.QuerySet[myapp.models.Other, TypedDict({'featured': builtins.bool})]" |
| 1523 | + Author().other_set.values("xyz") # E: Cannot resolve keyword 'xyz' into field. Choices are: authors, featured, id [misc] |
| 1524 | + reveal_type(Author().other_set.filter(featured=True).values_list("featured")) # N: Revealed type is "django.db.models.query.QuerySet[myapp.models.Other, Tuple[builtins.bool]]" |
| 1525 | + Author().other_set.filter(featured=True).values_list("xyz") # E: Cannot resolve keyword 'xyz' into field. Choices are: authors, featured, id [misc] |
| 1526 | + reveal_type(Author().other_set.filter(featured=True).values("featured")) # N: Revealed type is "django.db.models.query.QuerySet[myapp.models.Other, TypedDict({'featured': builtins.bool})]" |
| 1527 | + Author().other_set.filter(featured=True).values("xyz") # E: Cannot resolve keyword 'xyz' into field. Choices are: authors, featured, id [misc] |
1507 | 1528 | installed_apps: |
1508 | 1529 | - myapp |
1509 | 1530 | files: |
1510 | 1531 | - path: myapp/__init__.py |
1511 | 1532 | - path: myapp/models.py |
1512 | 1533 | content: | |
| 1534 | + from typing_extensions import Self |
1513 | 1535 | from django.db import models |
1514 | 1536 |
|
1515 | 1537 | class Author(models.Model): |
|
1518 | 1540 | class Book(models.Model): |
1519 | 1541 | featured = models.BooleanField(default=False) |
1520 | 1542 | authors = models.ManyToManyField(Author) |
| 1543 | +
|
| 1544 | + class OtherQuerySet(models.QuerySet["Other"]): |
| 1545 | + def custom(self) -> Self: ... |
| 1546 | +
|
| 1547 | + OtherManager = models.Manager.from_queryset(OtherQuerySet) |
| 1548 | + class Other(models.Model): |
| 1549 | + featured = models.BooleanField() |
| 1550 | + authors = models.ManyToManyField(Author) |
| 1551 | + objects = OtherManager() |
0 commit comments