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
0dad0ca5
Kaydet (Commit)
0dad0ca5
authored
Nis 21, 2014
tarafından
Aymeric Augustin
Dosyalara gözat
Seçenekler
Dosyalara Gözat
İndir
Eposta Yamaları
Sade Fark
[1.7.x] Further consolidated the model_inheritance tests.
Backport of
3f01e82c
from master
üst
ab0afef9
Hide whitespace changes
Inline
Side-by-side
Showing
5 changed files
with
27 additions
and
68 deletions
+27
-68
models.py
tests/model_inheritance_regress/models.py
+5
-0
tests.py
tests/model_inheritance_regress/tests.py
+22
-0
__init__.py
tests/model_inheritance_select_related/__init__.py
+0
-0
models.py
tests/model_inheritance_select_related/models.py
+0
-37
tests.py
tests/model_inheritance_select_related/tests.py
+0
-31
No files found.
tests/model_inheritance_regress/models.py
Dosyayı görüntüle @
0dad0ca5
...
@@ -73,9 +73,14 @@ class ParkingLot4B(Place, ParkingLot4):
...
@@ -73,9 +73,14 @@ class ParkingLot4B(Place, ParkingLot4):
pass
pass
@python_2_unicode_compatible
class
Supplier
(
models
.
Model
):
class
Supplier
(
models
.
Model
):
name
=
models
.
CharField
(
max_length
=
50
)
restaurant
=
models
.
ForeignKey
(
Restaurant
)
restaurant
=
models
.
ForeignKey
(
Restaurant
)
def
__str__
(
self
):
return
self
.
name
class
Wholesaler
(
Supplier
):
class
Wholesaler
(
Supplier
):
retailer
=
models
.
ForeignKey
(
Supplier
,
related_name
=
'wholesale_supplier'
)
retailer
=
models
.
ForeignKey
(
Supplier
,
related_name
=
'wholesale_supplier'
)
...
...
tests/model_inheritance_regress/tests.py
Dosyayı görüntüle @
0dad0ca5
...
@@ -466,3 +466,25 @@ class ModelInheritanceTest(TestCase):
...
@@ -466,3 +466,25 @@ class ModelInheritanceTest(TestCase):
serves_pizza
=
True
,
serves_hot_dogs
=
True
)
serves_pizza
=
True
,
serves_hot_dogs
=
True
)
p
=
Place
.
objects
.
all
()
.
select_related
(
'restaurant'
)[
0
]
p
=
Place
.
objects
.
all
()
.
select_related
(
'restaurant'
)[
0
]
self
.
assertIsInstance
(
p
.
restaurant
.
serves_pizza
,
bool
)
self
.
assertIsInstance
(
p
.
restaurant
.
serves_pizza
,
bool
)
def
test_inheritance_select_related
(
self
):
# Regression test for #7246
r1
=
Restaurant
.
objects
.
create
(
name
=
"Nobu"
,
serves_hot_dogs
=
True
,
serves_pizza
=
False
)
r2
=
Restaurant
.
objects
.
create
(
name
=
"Craft"
,
serves_hot_dogs
=
False
,
serves_pizza
=
True
)
Supplier
.
objects
.
create
(
name
=
"John"
,
restaurant
=
r1
)
Supplier
.
objects
.
create
(
name
=
"Jane"
,
restaurant
=
r2
)
self
.
assertQuerysetEqual
(
Supplier
.
objects
.
order_by
(
"name"
)
.
select_related
(),
[
"Jane"
,
"John"
,
],
attrgetter
(
"name"
)
)
jane
=
Supplier
.
objects
.
order_by
(
"name"
)
.
select_related
(
"restaurant"
)[
0
]
self
.
assertEqual
(
jane
.
restaurant
.
name
,
"Craft"
)
tests/model_inheritance_select_related/__init__.py
deleted
100644 → 0
Dosyayı görüntüle @
ab0afef9
tests/model_inheritance_select_related/models.py
deleted
100644 → 0
Dosyayı görüntüle @
ab0afef9
"""
Regression tests for the interaction between model inheritance and
select_related().
"""
from
__future__
import
unicode_literals
from
django.db
import
models
from
django.utils.encoding
import
python_2_unicode_compatible
@python_2_unicode_compatible
class
Place
(
models
.
Model
):
name
=
models
.
CharField
(
max_length
=
50
)
class
Meta
:
ordering
=
(
'name'
,)
def
__str__
(
self
):
return
"
%
s the place"
%
self
.
name
@python_2_unicode_compatible
class
Restaurant
(
Place
):
serves_sushi
=
models
.
BooleanField
(
default
=
False
)
serves_steak
=
models
.
BooleanField
(
default
=
False
)
def
__str__
(
self
):
return
"
%
s the restaurant"
%
self
.
name
@python_2_unicode_compatible
class
Person
(
models
.
Model
):
name
=
models
.
CharField
(
max_length
=
50
)
favorite_restaurant
=
models
.
ForeignKey
(
Restaurant
)
def
__str__
(
self
):
return
self
.
name
tests/model_inheritance_select_related/tests.py
deleted
100644 → 0
Dosyayı görüntüle @
ab0afef9
from
__future__
import
unicode_literals
from
operator
import
attrgetter
from
django.test
import
TestCase
from
.models
import
Restaurant
,
Person
class
ModelInheritanceSelectRelatedTests
(
TestCase
):
def
test_inherited_select_related
(
self
):
# Regression test for #7246
r1
=
Restaurant
.
objects
.
create
(
name
=
"Nobu"
,
serves_sushi
=
True
,
serves_steak
=
False
)
r2
=
Restaurant
.
objects
.
create
(
name
=
"Craft"
,
serves_sushi
=
False
,
serves_steak
=
True
)
Person
.
objects
.
create
(
name
=
"John"
,
favorite_restaurant
=
r1
)
Person
.
objects
.
create
(
name
=
"Jane"
,
favorite_restaurant
=
r2
)
self
.
assertQuerysetEqual
(
Person
.
objects
.
order_by
(
"name"
)
.
select_related
(),
[
"Jane"
,
"John"
,
],
attrgetter
(
"name"
)
)
jane
=
Person
.
objects
.
order_by
(
"name"
)
.
select_related
(
"favorite_restaurant"
)[
0
]
self
.
assertEqual
(
jane
.
favorite_restaurant
.
name
,
"Craft"
)
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