本文介紹 django.db.models.functions.Sqrt
的用法。
聲明
class Sqrt(expression, **extra)
返回非負數值字段或表達式的平方根。
使用示例:
>>> from django.db.models.functions import Sqrt
>>> Vector.objects.create(x=4.0, y=12.0)
>>> vector = Vector.objects.annotate(x_sqrt=Sqrt('x'), y_sqrt=Sqrt('y')).get()
>>> vector.x_sqrt, vector.y_sqrt
(2.0, 3.46410)
它也可以注冊為轉換。例如:
>>> from django.db.models import FloatField
>>> from django.db.models.functions import Sqrt
>>> FloatField.register_lookup(Sqrt)
>>> # Get vectors whose sqrt() is less than 5
>>> vectors = Vector.objects.filter(x__sqrt__lt=5, y__sqrt__lt=5)
相關用法
- Python Scipy integrate.quadrature()用法及代碼示例
- Python Scipy stats.hypsecant.moment()用法及代碼示例
- Python String Center()用法及代碼示例
- Python Django SimpleTestCase.client用法及代碼示例
- Python Django Signal用法及代碼示例
- Python Scipy stats.hypsecant.median()用法及代碼示例
- Python Sympy Ellipse.equation()用法及代碼示例
- Python String decode()用法及代碼示例
- Python String轉Binary用法及代碼示例
- Python String count()用法及代碼示例
- Python Scipy stats.halfgennorm.fit()用法及代碼示例
- Python Tableau Server用法及代碼示例
- Python Sympy encloses_point()用法及代碼示例
- Python String join()用法及代碼示例
- Python String casefold()用法及代碼示例
- Python Scipy stats.halfgennorm.stats()用法及代碼示例
- Python Set issubset()用法及代碼示例
- Python Sympy Plane.perpendicular_plane()用法及代碼示例
- Python Scipy stats.halfgennorm.moment()用法及代碼示例
- Python Scipy stats.halfgennorm.std()用法及代碼示例
- Python Scipy stats.halfgennorm.logcdf()用法及代碼示例
- Python String轉Long用法及代碼示例
- Python Django SearchHeadline用法及代碼示例
- Python String isalnum()用法及代碼示例
- Python Set issuperset()用法及代碼示例
注:本文由純淨天空篩選整理自djangoproject.com大神的英文原創作品 django.db.models.functions.Sqrt。非經特殊聲明,原始代碼版權歸原作者所有,本譯文未經允許或授權,請勿轉載或複製。