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
c3fdeb28
Kaydet (Commit)
c3fdeb28
authored
Ock 21, 2014
tarafından
Loic Bistuer
Kaydeden (comit)
Tim Graham
Ock 22, 2014
Dosyalara gözat
Seçenekler
Dosyalara Gözat
İndir
Eposta Yamaları
Sade Fark
Fixed #21846 -- Made NestedObjects handle related_name with %(app_label)s or %(class)s.
üst
a5ec11c4
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
32 additions
and
3 deletions
+32
-3
utils.py
django/contrib/admin/utils.py
+6
-2
models.py
tests/admin_util/models.py
+15
-0
tests.py
tests/admin_util/tests.py
+11
-1
No files found.
django/contrib/admin/utils.py
Dosyayı görüntüle @
c3fdeb28
...
@@ -156,10 +156,14 @@ class NestedObjects(Collector):
...
@@ -156,10 +156,14 @@ class NestedObjects(Collector):
def
add_edge
(
self
,
source
,
target
):
def
add_edge
(
self
,
source
,
target
):
self
.
edges
.
setdefault
(
source
,
[])
.
append
(
target
)
self
.
edges
.
setdefault
(
source
,
[])
.
append
(
target
)
def
collect
(
self
,
objs
,
source_attr
=
None
,
**
kwargs
):
def
collect
(
self
,
objs
,
source
=
None
,
source
_attr
=
None
,
**
kwargs
):
for
obj
in
objs
:
for
obj
in
objs
:
if
source_attr
:
if
source_attr
:
self
.
add_edge
(
getattr
(
obj
,
source_attr
),
obj
)
related_name
=
source_attr
%
{
'class'
:
source
.
_meta
.
model_name
,
'app_label'
:
source
.
_meta
.
app_label
,
}
self
.
add_edge
(
getattr
(
obj
,
related_name
),
obj
)
else
:
else
:
self
.
add_edge
(
None
,
obj
)
self
.
add_edge
(
None
,
obj
)
try
:
try
:
...
...
tests/admin_util/models.py
Dosyayı görüntüle @
c3fdeb28
...
@@ -47,3 +47,18 @@ class Guest(models.Model):
...
@@ -47,3 +47,18 @@ class Guest(models.Model):
class
EventGuide
(
models
.
Model
):
class
EventGuide
(
models
.
Model
):
event
=
models
.
ForeignKey
(
Event
,
on_delete
=
models
.
DO_NOTHING
)
event
=
models
.
ForeignKey
(
Event
,
on_delete
=
models
.
DO_NOTHING
)
class
Vehicle
(
models
.
Model
):
pass
class
VehicleMixin
(
Vehicle
):
vehicle
=
models
.
OneToOneField
(
Vehicle
,
parent_link
=
True
,
related_name
=
'vehicle_
%(app_label)
s_
%(class)
s'
)
class
Meta
:
abstract
=
True
class
Car
(
VehicleMixin
):
pass
tests/admin_util/tests.py
Dosyayı görüntüle @
c3fdeb28
...
@@ -16,7 +16,7 @@ from django.utils.formats import localize
...
@@ -16,7 +16,7 @@ from django.utils.formats import localize
from
django.utils.safestring
import
mark_safe
from
django.utils.safestring
import
mark_safe
from
django.utils
import
six
from
django.utils
import
six
from
.models
import
Article
,
Count
,
Event
,
Location
,
EventGuide
from
.models
import
Article
,
Count
,
Event
,
Location
,
EventGuide
,
Vehicle
,
Car
class
NestedObjectsTests
(
TestCase
):
class
NestedObjectsTests
(
TestCase
):
...
@@ -80,6 +80,16 @@ class NestedObjectsTests(TestCase):
...
@@ -80,6 +80,16 @@ class NestedObjectsTests(TestCase):
# One for Location, one for Guest, and no query for EventGuide
# One for Location, one for Guest, and no query for EventGuide
n
.
collect
(
objs
)
n
.
collect
(
objs
)
def
test_relation_on_abstract
(
self
):
"""
#21846 -- Check that `NestedObjects.collect()` doesn't trip
(AttributeError) on the special notation for relations on abstract
models (related_name that contains
%(app_label)
s and/or
%(class)
s).
"""
n
=
NestedObjects
(
using
=
DEFAULT_DB_ALIAS
)
Car
.
objects
.
create
()
n
.
collect
([
Vehicle
.
objects
.
first
()])
class
UtilTests
(
SimpleTestCase
):
class
UtilTests
(
SimpleTestCase
):
def
test_values_from_lookup_field
(
self
):
def
test_values_from_lookup_field
(
self
):
...
...
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