1

After crying under my desk for a while over this problem I got the courage to come on SO and ask this question. I have a django model: entry_time = models.DateTimeField(auto_now_add=True) On my admin change_form.html and change_list.html I would like to display that object in local time. I've read the django docs on this, my biggest problem I think is that I'm modifying the template and am not directly calling the object.

Settings.py:

TIME_ZONE = 'UTC'

USE_I18N = True

USE_L10N = True

USE_TZ = True

I have tried changing the TIME_ZONE to US/Arizona which didn't work. I tried solutions i found at Setting Django admin display times to local time? such as custom templates using

{% extends "admin/change_list.html" %}
{% load tz %}

{% block content %}
    {% timezone "US/Eastern" %}
        {{ block.super }}
    {% endtimezone %}
{% endblock %}

This did nothing, my time is still UTC on change_form. I tried installing a middleware package (awesome-django-timezones) that uses js to find local timezone and change it using middleware. This did nothing as well.

I also tried going into options.py and adding activate() into the view that calls change_form.html-- no success.

Am I missing something? How can I extend the admin templates to display local time? Is this a DB issue? I've read postgresql save the object and timezone and converts back and forth between UTC well, so I don't understand what my issue is.

Austin
  • 103
  • 10
  • I suggest backing up and finding a working configuration and then working forward from there. Start by setting `TIME_ZONE` to something else, and using the default admin templates. Does that work as you expect? Also, is the problem in how the existing field is displayed in the browser, or how the new value is interpreted by the server when saved? You should probably add a screenshot of the admin page to show what you're seeing, and explain why it's not what you expected. – Kevin Christopher Henry Sep 11 '20 at 23:47

0 Answers0