mirror of
https://github.com/django/django.git
synced 2025-07-24 13:44:32 +00:00
Fixed #30271 -- Added the Sign database function.
This commit is contained in:
parent
5935a9aead
commit
d26b242443
6 changed files with 88 additions and 2 deletions
|
@ -1099,6 +1099,31 @@ It can also be registered as a transform. For example::
|
|||
>>> # Get vectors whose round() is less than 20
|
||||
>>> vectors = Vector.objects.filter(x__round__lt=20, y__round__lt=20)
|
||||
|
||||
``Sign``
|
||||
--------
|
||||
|
||||
.. class:: Sign(expression, **extra)
|
||||
|
||||
.. versionadded:: 3.0
|
||||
|
||||
Returns the sign (-1, 0, 1) of a numeric field or expression.
|
||||
|
||||
Usage example::
|
||||
|
||||
>>> from django.db.models.functions import Sign
|
||||
>>> Vector.objects.create(x=5.4, y=-2.3)
|
||||
>>> vector = Vector.objects.annotate(x_sign=Sign('x'), y_sign=Sign('y')).get()
|
||||
>>> vector.x_sign, vector.y_sign
|
||||
(1, -1)
|
||||
|
||||
It can also be registered as a transform. For example::
|
||||
|
||||
>>> from django.db.models import FloatField
|
||||
>>> from django.db.models.functions import Sign
|
||||
>>> FloatField.register_lookup(Sign)
|
||||
>>> # Get vectors whose signs of components are less than 0.
|
||||
>>> vectors = Vector.objects.filter(x__sign__lt=0, y__sign__lt=0)
|
||||
|
||||
``Sin``
|
||||
-------
|
||||
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue