本文整理汇总了Python中MySQLdb.constants.FIELD_TYPE.TIME属性的典型用法代码示例。如果您正苦于以下问题:Python FIELD_TYPE.TIME属性的具体用法?Python FIELD_TYPE.TIME怎么用?Python FIELD_TYPE.TIME使用的例子?那么, 这里精选的属性代码示例或许可以为您提供帮助。您也可以进一步了解该属性所在类MySQLdb.constants.FIELD_TYPE
的用法示例。
在下文中一共展示了FIELD_TYPE.TIME属性的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: adapt_datetime_with_timezone_support
# 需要导入模块: from MySQLdb.constants import FIELD_TYPE [as 别名]
# 或者: from MySQLdb.constants.FIELD_TYPE import TIME [as 别名]
def adapt_datetime_with_timezone_support(value, conv):
# Equivalent to DateTimeField.get_db_prep_value. Used only by raw SQL.
if settings.USE_TZ:
if timezone.is_naive(value):
warnings.warn("MySQL received a naive datetime (%s)"
" while time zone support is active." % value,
RuntimeWarning)
default_timezone = timezone.get_default_timezone()
value = timezone.make_aware(value, default_timezone)
value = value.astimezone(timezone.utc).replace(tzinfo=None)
return Thing2Literal(value.strftime("%Y-%m-%d %H:%M:%S"), conv)
# MySQLdb-1.2.1 returns TIME columns as timedelta -- they are more like
# timedelta in terms of actual behavior as they are signed and include days --
# and Django expects time, so we still need to override that. We also need to
# add special handling for SafeText and SafeBytes as MySQLdb's type
# checking is too tight to catch those (see Django ticket #6052).
# Finally, MySQLdb always returns naive datetime objects. However, when
# timezone support is active, Django expects timezone-aware datetime objects.