I'm trying to get add a datetime to my form error message. Unfortunately it is rendered in UTC (my TIME_ZONE), but should be in the current timezone.
def clean(self):
# print(get_current_timezone()) > Europe/Berlin
cleaned_data = super(LegForm, self).clean()
departure_scheduled = cleaned_data.get('departure_scheduled')
# check departure in journey
if departure_scheduled < self.instance.journey.start:
journey_start = localize(self.instance.journey.start)
# print(self.instance.journey.start.tzinfo) > UTC
self.add_error(
'departure_scheduled',
_('Error Message (%(start)s).') % {'start': journey_start}
)
print(get_current_timezone())
returns Europe/Berlin
print(self.instance.journey.start.tzinfo)
returns UTC
The current timezone is activated. Is there any equal to localize()
to convert the datetime object to the current timezone?