Skip to content
Closed
Show file tree
Hide file tree
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
6 changes: 3 additions & 3 deletions .github/workflows/test.yml
Original file line number Diff line number Diff line change
Expand Up @@ -28,14 +28,14 @@ jobs:
run: pre-commit install && pre-commit run --all-files

test:
runs-on: ubuntu-latest
runs-on: macos-12
strategy:
matrix:
python-version: ['3.8']
python-version: ['3.10']
steps:
- uses: actions/checkout@v3
- name: Setup system dependencies
run: sudo apt-get install binutils libproj-dev gdal-bin
run: brew install proj gdal
- name: Set up Python ${{ matrix.python-version }}
uses: actions/setup-python@v4
with:
Expand Down
60 changes: 60 additions & 0 deletions tests/typecheck/managers/querysets/test_from_queryset.yml
Original file line number Diff line number Diff line change
Expand Up @@ -384,3 +384,63 @@
MyManager = BaseManager.from_queryset(MyQuerySet)
class MyModel(models.Model):
objects = MyManager()


- case: from_queryset_custom_auth_user_model
main: |
from this_name_must_be_unique.models import User
custom_settings: |
AUTH_USER_MODEL = "this_name_must_be_unique.User"
INSTALLED_APPS = ("django.contrib.auth", "django.contrib.contenttypes", "this_name_must_be_unique", "does_this_need_to_be_unique_too")
files:
- path: this_name_must_be_unique/__init__.py
- path: this_name_must_be_unique/models.py
content: |
from django.contrib.auth.models import AbstractBaseUser
from django.db import models

from .querysets import UserQuerySet

UserManager = models.Manager.from_queryset(UserQuerySet)

class User(AbstractBaseUser):
email = models.EmailField(unique=True)
objects = UserManager()
USERNAME_FIELD = "email"

- path: this_name_must_be_unique/querysets.py
content: |
from django.db import models
from typing import Optional, TYPE_CHECKING

if TYPE_CHECKING:
from .models import User

class UserQuerySet(models.QuerySet["User"]):
pass
- path: does_this_need_to_be_unique_too/__init__.py
- path: does_this_need_to_be_unique_too/models.py
content: |
from django.db import models
from .managers import MyManager, MyQuerySet
_MyManager = MyManager.from_queryset(MyQuerySet)
class MyModel(models.Model):
objects = _MyManager()
- path: does_this_need_to_be_unique_too/managers.py
content: |
from typing import TYPE_CHECKING, Optional

from django.db import models

if TYPE_CHECKING:
from .models import MyModel


class MyManager(models.Manager):
def my_manager_method(self) -> None:
...


class MyQuerySet(models.QuerySet["MyModel"]):
def my_method(self, arg: int) -> Optional["MyModel"]:
return self.first()