根据文件:If a Field has required=False and you pass clean() an empty value,
then clean() will return a normalized empty value rather than raising
ValidationError. For CharField, this will be a Unicode empty string.
For other Field classes, it might be None. (This varies from field to
field.)
正如Arun提到的,我做了字符串操作来确定时间:def set_hour_for_date(customer, hour_str, transaction_date):
meridian = hour_str[-2:]
hour = int(hour_str[:2])
if meridian == 'PM':
hour = hour + 12
relative_time = customer.time_zone.localize(datetime(
transaction_date.year,
transaction_date.month,
transaction_date.day,
hour,
0,
0,
294757))
return relative_time