Django audit log - 'action_date' field is naive, how do I prevent warnings -
i'm using django-audit-log track changes data. works great other 1 small thing: whenever new entry being added log table warning generated:
datetimefield received naive datetime while time zone support active.
i traced , discovered action_date field in log table causing it. know how can make value timezone-aware?
maybe pytz can come in handy here. can convert naive datetimes timezone aware ones. have here: http://pytz.sourceforge.net/.
if happen have naive date string "2012-02-21 10:28:45
", may proceed this:
from django.utils.dateparse import parse_datetime naive = parse_datetime("2012-02-21 10:28:45") import pytz pytz.timezone("europe/helsinki").localize(naive, is_dst=none) datetime.datetime(2012, 2, 21, 10, 28, 45, tzinfo=<dsttzinfo 'europe/helsinki' eet+2:00:00 std>
(https://docs.djangoproject.com/en/dev/topics/i18n/timezones/#usage).
Comments
Post a Comment