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
068d7568
Kaydet (Commit)
068d7568
authored
Mar 29, 2017
tarafından
Sergey Fedoseev
Kaydeden (comit)
Tim Graham
Mar 29, 2017
Dosyalara gözat
Seçenekler
Dosyalara Gözat
İndir
Eposta Yamaları
Sade Fark
Refs #18247 -- Fixed SQLite QuerySet filtering on decimal result of Least and Greatest.
üst
d5977e49
Hide whitespace changes
Inline
Side-by-side
Showing
4 changed files
with
29 additions
and
5 deletions
+29
-5
expressions.py
django/db/models/expressions.py
+2
-2
base.py
django/db/models/functions/base.py
+2
-2
models.py
tests/db_functions/models.py
+5
-0
tests.py
tests/db_functions/tests.py
+20
-1
No files found.
django/db/models/expressions.py
Dosyayı görüntüle @
068d7568
...
@@ -575,8 +575,8 @@ class Func(Expression):
...
@@ -575,8 +575,8 @@ class Func(Expression):
data
[
'expressions'
]
=
data
[
'field'
]
=
arg_joiner
.
join
(
sql_parts
)
data
[
'expressions'
]
=
data
[
'field'
]
=
arg_joiner
.
join
(
sql_parts
)
return
template
%
data
,
params
return
template
%
data
,
params
def
as_sqlite
(
self
,
compiler
,
connection
):
def
as_sqlite
(
self
,
compiler
,
connection
,
**
extra_context
):
sql
,
params
=
self
.
as_sql
(
compiler
,
connection
)
sql
,
params
=
self
.
as_sql
(
compiler
,
connection
,
**
extra_context
)
try
:
try
:
if
self
.
output_field
.
get_internal_type
()
==
'DecimalField'
:
if
self
.
output_field
.
get_internal_type
()
==
'DecimalField'
:
sql
=
'CAST(
%
s AS NUMERIC)'
%
sql
sql
=
'CAST(
%
s AS NUMERIC)'
%
sql
...
...
django/db/models/functions/base.py
Dosyayı görüntüle @
068d7568
...
@@ -132,7 +132,7 @@ class Greatest(Func):
...
@@ -132,7 +132,7 @@ class Greatest(Func):
def
as_sqlite
(
self
,
compiler
,
connection
):
def
as_sqlite
(
self
,
compiler
,
connection
):
"""Use the MAX function on SQLite."""
"""Use the MAX function on SQLite."""
return
super
()
.
as_sql
(
compiler
,
connection
,
function
=
'MAX'
)
return
super
()
.
as_sql
ite
(
compiler
,
connection
,
function
=
'MAX'
)
class
Least
(
Func
):
class
Least
(
Func
):
...
@@ -152,7 +152,7 @@ class Least(Func):
...
@@ -152,7 +152,7 @@ class Least(Func):
def
as_sqlite
(
self
,
compiler
,
connection
):
def
as_sqlite
(
self
,
compiler
,
connection
):
"""Use the MIN function on SQLite."""
"""Use the MIN function on SQLite."""
return
super
()
.
as_sql
(
compiler
,
connection
,
function
=
'MIN'
)
return
super
()
.
as_sql
ite
(
compiler
,
connection
,
function
=
'MIN'
)
class
Length
(
Transform
):
class
Length
(
Transform
):
...
...
tests/db_functions/models.py
Dosyayı görüntüle @
068d7568
...
@@ -49,3 +49,8 @@ class DTModel(models.Model):
...
@@ -49,3 +49,8 @@ class DTModel(models.Model):
def
__str__
(
self
):
def
__str__
(
self
):
return
'DTModel({0})'
.
format
(
self
.
name
)
return
'DTModel({0})'
.
format
(
self
.
name
)
class
DecimalModel
(
models
.
Model
):
n1
=
models
.
DecimalField
(
decimal_places
=
2
,
max_digits
=
6
)
n2
=
models
.
DecimalField
(
decimal_places
=
2
,
max_digits
=
6
)
tests/db_functions/tests.py
Dosyayı görüntüle @
068d7568
from
datetime
import
datetime
,
timedelta
from
datetime
import
datetime
,
timedelta
from
decimal
import
Decimal
from
unittest
import
skipIf
,
skipUnless
from
unittest
import
skipIf
,
skipUnless
from
django.db
import
connection
from
django.db
import
connection
...
@@ -11,7 +12,7 @@ from django.db.models.functions import (
...
@@ -11,7 +12,7 @@ from django.db.models.functions import (
from
django.test
import
TestCase
,
skipIfDBFeature
,
skipUnlessDBFeature
from
django.test
import
TestCase
,
skipIfDBFeature
,
skipUnlessDBFeature
from
django.utils
import
timezone
from
django.utils
import
timezone
from
.models
import
Article
,
Author
,
Fan
from
.models
import
Article
,
Author
,
DecimalModel
,
Fan
lorem_ipsum
=
"""
lorem_ipsum
=
"""
...
@@ -202,6 +203,15 @@ class FunctionTests(TestCase):
...
@@ -202,6 +203,15 @@ class FunctionTests(TestCase):
author
.
refresh_from_db
()
author
.
refresh_from_db
()
self
.
assertEqual
(
author
.
alias
,
'Jim'
)
self
.
assertEqual
(
author
.
alias
,
'Jim'
)
def
test_greatest_decimal_filter
(
self
):
obj
=
DecimalModel
.
objects
.
create
(
n1
=
Decimal
(
'1.1'
),
n2
=
Decimal
(
'1.2'
))
self
.
assertCountEqual
(
DecimalModel
.
objects
.
annotate
(
greatest
=
Greatest
(
'n1'
,
'n2'
),
)
.
filter
(
greatest
=
Decimal
(
'1.2'
)),
[
obj
],
)
def
test_least
(
self
):
def
test_least
(
self
):
now
=
timezone
.
now
()
now
=
timezone
.
now
()
before
=
now
-
timedelta
(
hours
=
1
)
before
=
now
-
timedelta
(
hours
=
1
)
...
@@ -297,6 +307,15 @@ class FunctionTests(TestCase):
...
@@ -297,6 +307,15 @@ class FunctionTests(TestCase):
author
.
refresh_from_db
()
author
.
refresh_from_db
()
self
.
assertEqual
(
author
.
alias
,
'James Smith'
)
self
.
assertEqual
(
author
.
alias
,
'James Smith'
)
def
test_least_decimal_filter
(
self
):
obj
=
DecimalModel
.
objects
.
create
(
n1
=
Decimal
(
'1.1'
),
n2
=
Decimal
(
'1.2'
))
self
.
assertCountEqual
(
DecimalModel
.
objects
.
annotate
(
least
=
Least
(
'n1'
,
'n2'
),
)
.
filter
(
least
=
Decimal
(
'1.1'
)),
[
obj
],
)
def
test_concat
(
self
):
def
test_concat
(
self
):
Author
.
objects
.
create
(
name
=
'Jayden'
)
Author
.
objects
.
create
(
name
=
'Jayden'
)
Author
.
objects
.
create
(
name
=
'John Smith'
,
alias
=
'smithj'
,
goes_by
=
'John'
)
Author
.
objects
.
create
(
name
=
'John Smith'
,
alias
=
'smithj'
,
goes_by
=
'John'
)
...
...
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