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
ceaf31ad
Kaydet (Commit)
ceaf31ad
authored
Mar 05, 2015
tarafından
Josh Smeaton
Dosyalara gözat
Seçenekler
Dosyalara Gözat
İndir
Eposta Yamaları
Sade Fark
Fixed #24420 -- Allowed ordering by case expressions
üst
82f7bee1
Show whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
47 additions
and
0 deletions
+47
-0
expressions.py
django/db/models/expressions.py
+5
-0
tests.py
tests/annotations/tests.py
+18
-0
tests.py
tests/expressions_case/tests.py
+24
-0
No files found.
django/db/models/expressions.py
Dosyayı görüntüle @
ceaf31ad
...
@@ -630,6 +630,11 @@ class Ref(ExpressionNode):
...
@@ -630,6 +630,11 @@ class Ref(ExpressionNode):
def
set_source_expressions
(
self
,
exprs
):
def
set_source_expressions
(
self
,
exprs
):
self
.
source
,
=
exprs
self
.
source
,
=
exprs
def
resolve_expression
(
self
,
query
=
None
,
allow_joins
=
True
,
reuse
=
None
,
summarize
=
False
,
for_save
=
False
):
# The sub-expression `source` has already been resolved, as this is
# just a reference to the name of `source`.
return
self
def
relabeled_clone
(
self
,
relabels
):
def
relabeled_clone
(
self
,
relabels
):
return
self
return
self
...
...
tests/annotations/tests.py
Dosyayı görüntüle @
ceaf31ad
...
@@ -280,6 +280,24 @@ class NonAggregateAnnotationTestCase(TestCase):
...
@@ -280,6 +280,24 @@ class NonAggregateAnnotationTestCase(TestCase):
book
=
Book
.
objects
.
annotate
(
no_value
=
Value
(
None
,
output_field
=
IntegerField
()))
.
first
()
book
=
Book
.
objects
.
annotate
(
no_value
=
Value
(
None
,
output_field
=
IntegerField
()))
.
first
()
self
.
assertIsNone
(
book
.
no_value
)
self
.
assertIsNone
(
book
.
no_value
)
def
test_order_by_annotation
(
self
):
authors
=
Author
.
objects
.
annotate
(
other_age
=
F
(
'age'
))
.
order_by
(
'other_age'
)
self
.
assertQuerysetEqual
(
authors
,
[
25
,
29
,
29
,
34
,
35
,
37
,
45
,
46
,
57
,
],
lambda
a
:
a
.
other_age
)
def
test_order_by_aggregate
(
self
):
authors
=
Author
.
objects
.
values
(
'age'
)
.
annotate
(
age_count
=
Count
(
'age'
))
.
order_by
(
'age_count'
,
'age'
)
self
.
assertQuerysetEqual
(
authors
,
[
(
25
,
1
),
(
34
,
1
),
(
35
,
1
),
(
37
,
1
),
(
45
,
1
),
(
46
,
1
),
(
57
,
1
),
(
29
,
2
),
],
lambda
a
:
(
a
[
'age'
],
a
[
'age_count'
])
)
def
test_column_field_ordering
(
self
):
def
test_column_field_ordering
(
self
):
"""
"""
Test that columns are aligned in the correct order for
Test that columns are aligned in the correct order for
...
...
tests/expressions_case/tests.py
Dosyayı görüntüle @
ceaf31ad
...
@@ -980,6 +980,30 @@ class CaseExpressionTests(TestCase):
...
@@ -980,6 +980,30 @@ class CaseExpressionTests(TestCase):
transform
=
attrgetter
(
'integer'
,
'integer2'
,
'test'
)
transform
=
attrgetter
(
'integer'
,
'integer2'
,
'test'
)
)
)
def
test_order_by_conditional_implicit
(
self
):
self
.
assertQuerysetEqual
(
CaseTestModel
.
objects
.
filter
(
integer__lte
=
2
)
.
annotate
(
test
=
Case
(
When
(
integer
=
1
,
then
=
2
),
When
(
integer
=
2
,
then
=
1
),
default
=
3
,
output_field
=
models
.
IntegerField
(),
))
.
order_by
(
'test'
,
'pk'
),
[(
2
,
1
),
(
2
,
1
),
(
1
,
2
)],
transform
=
attrgetter
(
'integer'
,
'test'
)
)
def
test_order_by_conditional_explicit
(
self
):
self
.
assertQuerysetEqual
(
CaseTestModel
.
objects
.
filter
(
integer__lte
=
2
)
.
annotate
(
test
=
Case
(
When
(
integer
=
1
,
then
=
2
),
When
(
integer
=
2
,
then
=
1
),
default
=
3
,
output_field
=
models
.
IntegerField
(),
))
.
order_by
(
F
(
'test'
)
.
asc
(),
'pk'
),
[(
2
,
1
),
(
2
,
1
),
(
1
,
2
)],
transform
=
attrgetter
(
'integer'
,
'test'
)
)
class
CaseDocumentationExamples
(
TestCase
):
class
CaseDocumentationExamples
(
TestCase
):
@classmethod
@classmethod
...
...
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