Skip to content
Projeler
Gruplar
Parçacıklar
Yardım
Yükleniyor...
Oturum aç / Kaydol
Gezinmeyi değiştir
D
django
Proje
Proje
Ayrıntılar
Etkinlik
Cycle Analytics
Depo (repository)
Depo (repository)
Dosyalar
Kayıtlar (commit)
Dallar (branch)
Etiketler
Katkıda bulunanlar
Grafik
Karşılaştır
Grafikler
Konular (issue)
0
Konular (issue)
0
Liste
Pano
Etiketler
Kilometre Taşları
Birleştirme (merge) Talepleri
0
Birleştirme (merge) Talepleri
0
CI / CD
CI / CD
İş akışları (pipeline)
İşler
Zamanlamalar
Grafikler
Paketler
Paketler
Wiki
Wiki
Parçacıklar
Parçacıklar
Üyeler
Üyeler
Collapse sidebar
Close sidebar
Etkinlik
Grafik
Grafikler
Yeni bir konu (issue) oluştur
İşler
Kayıtlar (commit)
Konu (issue) Panoları
Kenar çubuğunu aç
Batuhan Osman TASKAYA
django
Commits
c550beb0
Kaydet (Commit)
c550beb0
authored
Kas 09, 2015
tarafından
Simon Charette
Dosyalara gözat
Seçenekler
Dosyalara Gözat
İndir
Eposta Yamaları
Sade Fark
Fixed #25723 -- Made related field checks lookup against their local apps.
üst
c819780d
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
71 additions
and
3 deletions
+71
-3
related.py
django/db/models/fields/related.py
+3
-3
test_relative_fields.py
tests/invalid_models_tests/test_relative_fields.py
+68
-0
No files found.
django/db/models/fields/related.py
Dosyayı görüntüle @
c550beb0
...
@@ -147,7 +147,7 @@ class RelatedField(Field):
...
@@ -147,7 +147,7 @@ class RelatedField(Field):
return
[]
return
[]
def
_check_relation_model_exists
(
self
):
def
_check_relation_model_exists
(
self
):
rel_is_missing
=
self
.
remote_field
.
model
not
in
apps
.
get_models
()
rel_is_missing
=
self
.
remote_field
.
model
not
in
self
.
opts
.
apps
.
get_models
()
rel_is_string
=
isinstance
(
self
.
remote_field
.
model
,
six
.
string_types
)
rel_is_string
=
isinstance
(
self
.
remote_field
.
model
,
six
.
string_types
)
model_name
=
self
.
remote_field
.
model
if
rel_is_string
else
self
.
remote_field
.
model
.
_meta
.
object_name
model_name
=
self
.
remote_field
.
model
if
rel_is_string
else
self
.
remote_field
.
model
.
_meta
.
object_name
if
rel_is_missing
and
(
rel_is_string
or
not
self
.
remote_field
.
model
.
_meta
.
swapped
):
if
rel_is_missing
and
(
rel_is_string
or
not
self
.
remote_field
.
model
.
_meta
.
swapped
):
...
@@ -163,7 +163,7 @@ class RelatedField(Field):
...
@@ -163,7 +163,7 @@ class RelatedField(Field):
return
[]
return
[]
def
_check_referencing_to_swapped_model
(
self
):
def
_check_referencing_to_swapped_model
(
self
):
if
(
self
.
remote_field
.
model
not
in
apps
.
get_models
()
and
if
(
self
.
remote_field
.
model
not
in
self
.
opts
.
apps
.
get_models
()
and
not
isinstance
(
self
.
remote_field
.
model
,
six
.
string_types
)
and
not
isinstance
(
self
.
remote_field
.
model
,
six
.
string_types
)
and
self
.
remote_field
.
model
.
_meta
.
swapped
):
self
.
remote_field
.
model
.
_meta
.
swapped
):
model
=
"
%
s.
%
s"
%
(
model
=
"
%
s.
%
s"
%
(
...
@@ -1197,7 +1197,7 @@ class ManyToManyField(RelatedField):
...
@@ -1197,7 +1197,7 @@ class ManyToManyField(RelatedField):
errors
=
[]
errors
=
[]
if
self
.
remote_field
.
through
not
in
apps
.
get_models
(
include_auto_created
=
True
):
if
self
.
remote_field
.
through
not
in
self
.
opts
.
apps
.
get_models
(
include_auto_created
=
True
):
# The relationship model is not installed.
# The relationship model is not installed.
errors
.
append
(
errors
.
append
(
checks
.
Error
(
checks
.
Error
(
...
...
tests/invalid_models_tests/test_relative_fields.py
Dosyayı görüntüle @
c550beb0
...
@@ -3,6 +3,7 @@ from __future__ import unicode_literals
...
@@ -3,6 +3,7 @@ from __future__ import unicode_literals
import
warnings
import
warnings
from
django.apps.registry
import
Apps
from
django.core.checks
import
Error
,
Warning
as
DjangoWarning
from
django.core.checks
import
Error
,
Warning
as
DjangoWarning
from
django.db
import
models
from
django.db
import
models
from
django.db.models.fields.related
import
ForeignObject
from
django.db.models.fields.related
import
ForeignObject
...
@@ -132,6 +133,26 @@ class RelativeFieldTests(IsolatedModelsTestCase):
...
@@ -132,6 +133,26 @@ class RelativeFieldTests(IsolatedModelsTestCase):
]
]
self
.
assertEqual
(
errors
,
expected
)
self
.
assertEqual
(
errors
,
expected
)
def
test_foreign_key_to_isolated_apps_model
(
self
):
"""
#25723 - Referenced model registration lookup should be run against the
field's model registry.
"""
test_apps
=
Apps
([
'invalid_models_tests'
])
class
OtherModel
(
models
.
Model
):
class
Meta
:
apps
=
test_apps
class
Model
(
models
.
Model
):
foreign_key
=
models
.
ForeignKey
(
'OtherModel'
,
models
.
CASCADE
)
class
Meta
:
apps
=
test_apps
field
=
Model
.
_meta
.
get_field
(
'foreign_key'
)
self
.
assertEqual
(
field
.
check
(
from_model
=
Model
),
[])
def
test_many_to_many_to_missing_model
(
self
):
def
test_many_to_many_to_missing_model
(
self
):
class
Model
(
models
.
Model
):
class
Model
(
models
.
Model
):
m2m
=
models
.
ManyToManyField
(
"Rel2"
)
m2m
=
models
.
ManyToManyField
(
"Rel2"
)
...
@@ -149,6 +170,26 @@ class RelativeFieldTests(IsolatedModelsTestCase):
...
@@ -149,6 +170,26 @@ class RelativeFieldTests(IsolatedModelsTestCase):
]
]
self
.
assertEqual
(
errors
,
expected
)
self
.
assertEqual
(
errors
,
expected
)
def
test_many_to_many_to_isolated_apps_model
(
self
):
"""
#25723 - Referenced model registration lookup should be run against the
field's model registry.
"""
test_apps
=
Apps
([
'invalid_models_tests'
])
class
OtherModel
(
models
.
Model
):
class
Meta
:
apps
=
test_apps
class
Model
(
models
.
Model
):
m2m
=
models
.
ManyToManyField
(
'OtherModel'
)
class
Meta
:
apps
=
test_apps
field
=
Model
.
_meta
.
get_field
(
'm2m'
)
self
.
assertEqual
(
field
.
check
(
from_model
=
Model
),
[])
def
test_many_to_many_with_useless_options
(
self
):
def
test_many_to_many_with_useless_options
(
self
):
class
Model
(
models
.
Model
):
class
Model
(
models
.
Model
):
name
=
models
.
CharField
(
max_length
=
20
)
name
=
models
.
CharField
(
max_length
=
20
)
...
@@ -288,6 +329,33 @@ class RelativeFieldTests(IsolatedModelsTestCase):
...
@@ -288,6 +329,33 @@ class RelativeFieldTests(IsolatedModelsTestCase):
]
]
self
.
assertEqual
(
errors
,
expected
)
self
.
assertEqual
(
errors
,
expected
)
def
test_many_to_many_through_isolated_apps_model
(
self
):
"""
#25723 - Through model registration lookup should be run against the
field's model registry.
"""
test_apps
=
Apps
([
'invalid_models_tests'
])
class
GroupMember
(
models
.
Model
):
person
=
models
.
ForeignKey
(
'Person'
,
models
.
CASCADE
)
group
=
models
.
ForeignKey
(
'Group'
,
models
.
CASCADE
)
class
Meta
:
apps
=
test_apps
class
Person
(
models
.
Model
):
class
Meta
:
apps
=
test_apps
class
Group
(
models
.
Model
):
members
=
models
.
ManyToManyField
(
'Person'
,
through
=
'GroupMember'
)
class
Meta
:
apps
=
test_apps
field
=
Group
.
_meta
.
get_field
(
'members'
)
self
.
assertEqual
(
field
.
check
(
from_model
=
Group
),
[])
def
test_symmetrical_self_referential_field
(
self
):
def
test_symmetrical_self_referential_field
(
self
):
class
Person
(
models
.
Model
):
class
Person
(
models
.
Model
):
# Implicit symmetrical=False.
# Implicit symmetrical=False.
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment