本文介紹 django.db.models.functions.Abs
的用法。
聲明
class Abs(expression, **extra)
返回數值字段或表達式的絕對值。
使用示例:
>>> from django.db.models.functions import Abs
>>> Vector.objects.create(x=-0.5, y=1.1)
>>> vector = Vector.objects.annotate(x_abs=Abs('x'), y_abs=Abs('y')).get()
>>> vector.x_abs, vector.y_abs
(0.5, 1.1)
它也可以注冊為轉換。例如:
>>> from django.db.models import FloatField
>>> from django.db.models.functions import Abs
>>> FloatField.register_lookup(Abs)
>>> # Get vectors inside the unit cube
>>> vectors = Vector.objects.filter(x__abs__lt=1, y__abs__lt=1)
相關用法
- Python Tweepy API.mentions_timeline()用法及代碼示例
- Python Tweepy API.get_user()用法及代碼示例
- Python Tweepy API.list_timeline()用法及代碼示例
- Python Django ACos用法及代碼示例
- Python Django Area用法及代碼示例
- Python Tweepy API.add_list_members()用法及代碼示例
- Python Django AuthenticationForm.confirm_login_allowed用法及代碼示例
- Python Tweepy API.create_block()用法及代碼示例
- Python Django ATan用法及代碼示例
- Python Tweepy API.trends_closest()用法及代碼示例
- Python Django ArchiveIndexView用法及代碼示例
- Python Tweepy API.send_direct_message()用法及代碼示例
- Python Tweepy API.destroy_status()用法及代碼示例
- Python Tweepy API.destroy_saved_search()用法及代碼示例
- Python Django ArraySubquery用法及代碼示例
- Python Tweepy API.get_list()用法及代碼示例
- Python Tweepy API.favorites()用法及代碼示例
- Python Tweepy API.blocks_ids()用法及代碼示例
- Python Tweepy API.configuration()用法及代碼示例
- Python Tweepy API.lists_memberships()用法及代碼示例
- Python Tweepy API.home_timeline()用法及代碼示例
- Python Tweepy API.unretweet()用法及代碼示例
- Python Tweepy API.create_mute()用法及代碼示例
- Python Tweepy API.search_users()用法及代碼示例
- Python Tweepy API.show_list_member()用法及代碼示例
注:本文由純淨天空篩選整理自djangoproject.com大神的英文原創作品 django.db.models.functions.Abs。非經特殊聲明,原始代碼版權歸原作者所有,本譯文未經允許或授權,請勿轉載或複製。