-
Notifications
You must be signed in to change notification settings - Fork 117
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Rely on Django to resolve string references in ForeignKey fields. Refs …
…#243 this commit tries to load & configure Django and use its internal machinery to resolve apps and models in case they are referenced as a string. If this fails it falls back to appending ".models" to the first part of the name and looking for a module with that name to augment.
- Loading branch information
1 parent
6df2eeb
commit ec4f005
Showing
8 changed files
with
53 additions
and
5 deletions.
There are no files selected for viewing
11 changes: 11 additions & 0 deletions
11
pylint_django/tests/input/func_noerror_string_foreignkey.py
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,11 @@ | ||
""" | ||
Checks that PyLint correctly handles string foreign keys | ||
https://github.com/PyCQA/pylint-django/issues/243 | ||
""" | ||
# pylint: disable=missing-docstring | ||
from django.db import models | ||
|
||
|
||
class Book(models.Model): | ||
author = models.ForeignKey("test_app.Author", models.CASCADE) | ||
user = models.ForeignKey("auth.User", models.PROTECT) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -3,4 +3,5 @@ | |
|
||
|
||
class Author(models.Model): | ||
pass | ||
class Meta: | ||
app_label = 'test_app' |
Empty file.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
from django.apps import AppConfig | ||
|
||
|
||
class TestAppConfig(AppConfig): | ||
name = 'test_app' |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
from models.author import Author # noqa: F401 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,12 @@ | ||
SECRET_KEY = 'fake-key' | ||
|
||
INSTALLED_APPS = [ | ||
'django.contrib.auth', | ||
'django.contrib.contenttypes', | ||
'test_app', | ||
] | ||
|
||
MIDDLEWARE = [ | ||
'django.contrib.sessions.middleware.SessionMiddleware', | ||
'django.contrib.auth.middleware.AuthenticationMiddleware', | ||
] |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters