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
d04e7302
Kaydet (Commit)
d04e7302
authored
May 27, 2014
tarafından
Vincent-Vega
Kaydeden (comit)
Simon Charette
Haz 01, 2014
Dosyalara gözat
Seçenekler
Dosyalara Gözat
İndir
Eposta Yamaları
Sade Fark
Fixed #22711 -- Adjusted ordering checks to allow implicit relation fields.
refs #19195.
üst
7a38f889
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
43 additions
and
1 deletion
+43
-1
base.py
django/db/models/base.py
+9
-1
test_models.py
tests/invalid_models_tests/test_models.py
+34
-0
No files found.
django/db/models/base.py
Dosyayı görüntüle @
d04e7302
...
...
@@ -1357,7 +1357,7 @@ class Model(six.with_metaclass(ModelBase)):
@classmethod
def
_check_ordering
(
cls
):
""" Check "ordering" option -- is it a list of
list
s and do all fields
""" Check "ordering" option -- is it a list of
string
s and do all fields
exist? """
from
django.db.models
import
FieldDoesNotExist
...
...
@@ -1401,6 +1401,14 @@ class Model(six.with_metaclass(ModelBase)):
try
:
cls
.
_meta
.
get_field
(
field_name
,
many_to_many
=
False
)
except
FieldDoesNotExist
:
if
field_name
.
endswith
(
'_id'
):
try
:
field
=
cls
.
_meta
.
get_field
(
field_name
[:
-
3
],
many_to_many
=
False
)
except
FieldDoesNotExist
:
pass
else
:
if
field
.
attname
==
field_name
:
continue
errors
.
append
(
checks
.
Error
(
"'ordering' refers to the non-existent field '
%
s'."
%
field_name
,
...
...
tests/invalid_models_tests/test_models.py
Dosyayı görüntüle @
d04e7302
...
...
@@ -415,6 +415,40 @@ class OtherModelTests(IsolatedModelsTestCase):
]
self
.
assertEqual
(
errors
,
expected
)
def
test_ordering_pointing_to_missing_foreignkey_field
(
self
):
# refs #22711
class
Model
(
models
.
Model
):
missing_fk_field
=
models
.
IntegerField
()
class
Meta
:
ordering
=
(
"missing_fk_field_id"
,)
errors
=
Model
.
check
()
expected
=
[
Error
(
"'ordering' refers to the non-existent field 'missing_fk_field_id'."
,
hint
=
None
,
obj
=
Model
,
id
=
'models.E015'
,
)
]
self
.
assertEqual
(
errors
,
expected
)
def
test_ordering_pointing_to_existing_foreignkey_field
(
self
):
# refs #22711
class
Parent
(
models
.
Model
):
pass
class
Child
(
models
.
Model
):
parent
=
models
.
ForeignKey
(
Parent
)
class
Meta
:
ordering
=
(
"parent_id"
,)
self
.
assertFalse
(
Child
.
check
())
@override_settings
(
TEST_SWAPPED_MODEL_BAD_VALUE
=
'not-a-model'
)
def
test_swappable_missing_app_name
(
self
):
class
Model
(
models
.
Model
):
...
...
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