本文介紹 django.db.models.functions.Cast
的用法。
聲明
class Cast(expression, output_field)
強製 expression
的結果類型為來自 output_field
的結果類型。
使用示例:
>>> from django.db.models import FloatField
>>> from django.db.models.functions import Cast
>>> Author.objects.create(age=25, name='Margaret Smith')
>>> author = Author.objects.annotate(
... age_as_float=Cast('age', output_field=FloatField()),
... ).get()
>>> print(author.age_as_float)
25.0
相關用法
- Python Django Case用法及代碼示例
- Python Calendar itermonthdays2()用法及代碼示例
- Python Calendar monthdatescalendar()用法及代碼示例
- Python Calendar itermonthdates()用法及代碼示例
- Python Calendar iterweekdays()用法及代碼示例
- Python Calendar monthdayscalendar()用法及代碼示例
- Python Calendar itermonthdays3()用法及代碼示例
- Python Calendar yeardatescalendar()用法及代碼示例
- Python Django CallbackFilter用法及代碼示例
- Python Calendar itermonthdays()用法及代碼示例
- Python Calendar yeardayscalendar()用法及代碼示例
- Python Calendar yeardays2calendar()用法及代碼示例
- Python Calendar itermonthdays4()用法及代碼示例
- Python Calendar monthdays2calendar()用法及代碼示例
- Python OpenCV Canny()用法及代碼示例
- Python Tableau CSVRequestOptions用法及代碼示例
- Python Django ContentTypeManager用法及代碼示例
- Python Condition release()用法及代碼示例
- Python Collections.UserString用法及代碼示例
- Python Condition notify()用法及代碼示例
- Python CSV轉JSON用法及代碼示例
- Python Django ContextMixin.get_context_data用法及代碼示例
- Python Django CustomUserManager.create_user用法及代碼示例
- Python Condition wait()用法及代碼示例
- Python Django Coalesce用法及代碼示例
注:本文由純淨天空篩選整理自djangoproject.com大神的英文原創作品 django.db.models.functions.Cast。非經特殊聲明,原始代碼版權歸原作者所有,本譯文未經允許或授權,請勿轉載或複製。