diff options
| author | Nick Pope <nick.pope@flightdataservices.com> | 2019-03-20 08:27:34 +0000 |
|---|---|---|
| committer | Mariusz Felisiak <felisiak.mariusz@gmail.com> | 2019-03-22 12:52:39 +0100 |
| commit | d26b2424437dabeeca94d7900b37d2df4410da0c (patch) | |
| tree | cb08383bf787f14b91e82664ebedf84c92748e51 /django | |
| parent | 5935a9aeade517aebdceea989467d2b46c44d96f (diff) | |
Fixed #30271 -- Added the Sign database function.
Diffstat (limited to 'django')
| -rw-r--r-- | django/db/backends/sqlite3/base.py | 1 | ||||
| -rw-r--r-- | django/db/models/functions/__init__.py | 4 | ||||
| -rw-r--r-- | django/db/models/functions/math.py | 5 |
3 files changed, 8 insertions, 2 deletions
diff --git a/django/db/backends/sqlite3/base.py b/django/db/backends/sqlite3/base.py index 7552956cd9..6a19236c48 100644 --- a/django/db/backends/sqlite3/base.py +++ b/django/db/backends/sqlite3/base.py @@ -231,6 +231,7 @@ class DatabaseWrapper(BaseDatabaseWrapper): conn.create_function('SHA256', 1, none_guard(lambda x: hashlib.sha256(x.encode()).hexdigest())) conn.create_function('SHA384', 1, none_guard(lambda x: hashlib.sha384(x.encode()).hexdigest())) conn.create_function('SHA512', 1, none_guard(lambda x: hashlib.sha512(x.encode()).hexdigest())) + conn.create_function('SIGN', 1, none_guard(lambda x: (x > 0) - (x < 0))) conn.create_function('SIN', 1, none_guard(math.sin)) conn.create_function('SQRT', 1, none_guard(math.sqrt)) conn.create_function('TAN', 1, none_guard(math.tan)) diff --git a/django/db/models/functions/__init__.py b/django/db/models/functions/__init__.py index fb899127d2..c928873661 100644 --- a/django/db/models/functions/__init__.py +++ b/django/db/models/functions/__init__.py @@ -7,7 +7,7 @@ from .datetime import ( ) from .math import ( Abs, ACos, ASin, ATan, ATan2, Ceil, Cos, Cot, Degrees, Exp, Floor, Ln, Log, - Mod, Pi, Power, Radians, Round, Sin, Sqrt, Tan, + Mod, Pi, Power, Radians, Round, Sign, Sin, Sqrt, Tan, ) from .text import ( MD5, SHA1, SHA224, SHA256, SHA384, SHA512, Chr, Concat, ConcatPair, Left, @@ -32,7 +32,7 @@ __all__ = [ # math 'Abs', 'ACos', 'ASin', 'ATan', 'ATan2', 'Ceil', 'Cos', 'Cot', 'Degrees', 'Exp', 'Floor', 'Ln', 'Log', 'Mod', 'Pi', 'Power', 'Radians', 'Round', - 'Sin', 'Sqrt', 'Tan', + 'Sign', 'Sin', 'Sqrt', 'Tan', # text 'MD5', 'SHA1', 'SHA224', 'SHA256', 'SHA384', 'SHA512', 'Chr', 'Concat', 'ConcatPair', 'Left', 'Length', 'Lower', 'LPad', 'LTrim', 'Ord', 'Repeat', diff --git a/django/db/models/functions/math.py b/django/db/models/functions/math.py index 1a574eb9ab..909a3088bb 100644 --- a/django/db/models/functions/math.py +++ b/django/db/models/functions/math.py @@ -146,6 +146,11 @@ class Round(Transform): lookup_name = 'round' +class Sign(Transform): + function = 'SIGN' + lookup_name = 'sign' + + class Sin(NumericOutputFieldMixin, Transform): function = 'SIN' lookup_name = 'sin' |
