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
a3baee2f
Kaydet (Commit)
a3baee2f
authored
Kas 11, 2015
tarafından
Simon Charette
Dosyalara gözat
Seçenekler
Dosyalara Gözat
İndir
Eposta Yamaları
Sade Fark
[1.8.x] Refs #25693 -- Avoided redundant calls to get_fields() in `to_attr` validation.
Backport of
4a9c32f5
from master
üst
74a56644
Show whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
11 additions
and
8 deletions
+11
-8
query.py
django/db/models/query.py
+11
-8
No files found.
django/db/models/query.py
Dosyayı görüntüle @
a3baee2f
...
...
@@ -1631,20 +1631,23 @@ def prefetch_one_level(instances, prefetcher, lookup, level):
rel_attr_val
=
rel_obj_attr
(
rel_obj
)
rel_obj_cache
.
setdefault
(
rel_attr_val
,
[])
.
append
(
rel_obj
)
for
obj
in
instances
:
instance_attr_val
=
instance_attr
(
obj
)
vals
=
rel_obj_cache
.
get
(
instance_attr_val
,
[])
to_attr
,
as_attr
=
lookup
.
get_current_to_attr
(
level
)
# Check we are not shadowing a field on obj.
if
as_attr
:
# Make sure `to_attr` does not conflict with a field.
if
as_attr
and
instances
:
# We assume that objects retrieved are homogeneous (which is the premise
# of prefetch_related), so what applies to first object applies to all.
model
=
instances
[
0
]
.
__class__
try
:
field
=
obj
.
_meta
.
get_field
(
to_attr
)
model
.
_meta
.
get_field
(
to_attr
)
except
exceptions
.
FieldDoesNotExist
:
pass
else
:
msg
=
'to_attr={} conflicts with a field on the {} model.'
raise
ValueError
(
msg
.
format
(
to_attr
,
field
.
model
.
__name__
))
raise
ValueError
(
msg
.
format
(
to_attr
,
model
.
__name__
))
for
obj
in
instances
:
instance_attr_val
=
instance_attr
(
obj
)
vals
=
rel_obj_cache
.
get
(
instance_attr_val
,
[])
if
single
:
val
=
vals
[
0
]
if
vals
else
None
...
...
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