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
06acb344
Kaydet (Commit)
06acb344
authored
Haz 29, 2016
tarafından
David Sanders
Kaydeden (comit)
Tim Graham
Haz 29, 2016
Dosyalara gözat
Seçenekler
Dosyalara Gözat
İndir
Eposta Yamaları
Sade Fark
Added a test for updating an annotated queryset.
üst
18571aef
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
20 additions
and
0 deletions
+20
-0
tests.py
tests/update/tests.py
+20
-0
No files found.
tests/update/tests.py
Dosyayı görüntüle @
06acb344
from
__future__
import
unicode_literals
from
django.core.exceptions
import
FieldError
from
django.db.models
import
F
,
Max
from
django.test
import
TestCase
from
.models
import
A
,
B
,
Bar
,
D
,
DataPoint
,
Foo
,
RelatedPoint
...
...
@@ -138,3 +140,21 @@ class AdvancedTests(TestCase):
self
.
assertEqual
(
bar_qs
[
0
]
.
foo_id
,
a_foo
.
target
)
bar_qs
.
update
(
foo
=
b_foo
)
self
.
assertEqual
(
bar_qs
[
0
]
.
foo_id
,
b_foo
.
target
)
def
test_update_annotated_queryset
(
self
):
"""
Update of a queryset that's been annotated.
"""
# Trivial annotated update
qs
=
DataPoint
.
objects
.
annotate
(
alias
=
F
(
'value'
))
self
.
assertEqual
(
qs
.
update
(
another_value
=
'foo'
),
3
)
# Update where annotation is used for filtering
qs
=
DataPoint
.
objects
.
annotate
(
alias
=
F
(
'value'
))
.
filter
(
alias
=
'apple'
)
self
.
assertEqual
(
qs
.
update
(
another_value
=
'foo'
),
1
)
# Update where annotation is used in update parameters
qs
=
DataPoint
.
objects
.
annotate
(
alias
=
F
(
'value'
))
self
.
assertEqual
(
qs
.
update
(
another_value
=
F
(
'alias'
)),
3
)
# Update where aggregation annotation is used in update parameters
qs
=
DataPoint
.
objects
.
annotate
(
max
=
Max
(
'value'
))
with
self
.
assertRaisesMessage
(
FieldError
,
'Aggregate functions are not allowed in this query'
):
qs
.
update
(
another_value
=
F
(
'max'
))
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