Skip to content Skip to sidebar Skip to footer

Django Admin: Timezone Display

So i am making an app where you can find activities which happen at locations. On the django-admin page i want to be able to modify Activities (which works). However an activity ha

Solution 1:

"So i want it to display the start time, on the activity admin page, in the same timezone as the location is in, but then when saved it should be converted to UTC time."

According to Django's documentation on Time zone aware input in forms (https://docs.djangoproject.com/en/1.10/topics/i18n/timezones/#time-zone-aware-input-in-forms):

When you enable time zone support, Django interprets datetimes entered in forms in the current time zone and returns aware datetime objects in cleaned_data.

Which from what I understood is what you want. This leads us to Default time zone and current time zone (https://docs.djangoproject.com/en/1.10/topics/i18n/timezones/#default-current-time-zone), which states:

The current time zone is the time zone that’s used for rendering.

You should set the current time zone to the end user’s actual time zone with activate(). Otherwise, the default time zone is used.

So, use activate() (https://docs.djangoproject.com/en/1.10/ref/utils/#django.utils.timezone.activate) to set timezone argument and you're good to go.


Solution 2:

Try to set
USE_L10N = False on settings.py:

https://docs.djangoproject.com/en/1.9/ref/settings/#use-l10n


Post a Comment for "Django Admin: Timezone Display"