allow custom app label for ForeignKey

This commit is contained in:
Maxim Kurnikov
2019-07-20 22:50:37 +03:00
parent fa57fb0cbf
commit b86d33c718
2 changed files with 30 additions and 0 deletions

View File

@@ -50,6 +50,9 @@ def initialize_django(settings_module: str) -> Tuple['Apps', 'LazySettings']:
apps.get_models.cache_clear()
apps.get_swappable_settings_name.cache_clear()
if not settings.configured:
settings._setup()
apps.populate(settings.INSTALLED_APPS)
assert apps.apps_ready

View File

@@ -451,3 +451,30 @@
class Book(models.Model):
publisher = models.ForeignKey(to=settings.BOOK_RELATED_MODEL, on_delete=models.CASCADE,
related_name='books')
- case: foreign_key_with_custom_app_name
main: |
from myapp.models import MyMain
reveal_type(MyMain().user) # N: Revealed type is 'myapp2.models.MyUser*'
installed_apps:
- myapp
- myapp2.apps.MyApp2Config
files:
- path: myapp/__init__.py
- path: myapp/models.py
content: |
from django.db import models
class MyMain(models.Model):
user = models.ForeignKey('myapp2__user.MyUser', on_delete=models.CASCADE)
- path: myapp2/__init__.py
- path: myapp2/models.py
content: |
from django.db import models
class MyUser(models.Model):
pass
- path: myapp2/apps.py
content: |
from django.apps.config import AppConfig
class MyApp2Config(AppConfig):
name = 'myapp2'
label = 'myapp2__user'