I'm trying to make it so the datetime field attribute of a model object is displayed in the template as the local time of the timezone of the current user. The default timezone in my settings is UTC. Here is an example model:
models.py
class Basic(models.Model):
name = models.CharField(max_length=128)
created_at = models.DateTimeField(auto_now_add=True
The data I want to display is in a table made with django-tables2. However, I already tried two methods and both of them did not work:
tables.py attempt 1:
class ShipperDataFileDocumentTable(tables.Table):
created_at = tables.TemplateColumn('''
{% load tz %}
{% localtime on %}
{{ record.created_at }}
{% endlocaltime %}
''')
class Meta:
model = Basic
fields = ('name', 'created_at')
tables.py attempt 2:
class ShipperDataFileDocumentTable(tables.Table):
created_at = tables.TemplateColumn('''
{% load tz %}
{{ record.created_at|localtime }}
''')
class Meta:
model = Basic
fields = ('name', 'created_at')
Both of these methods ended up not changing the time at all. For example, I made an object at 12:00 PM EST. Normally, the template would display it as 4:00 PM in UTC. However, even with those edits, it still displayed the time as 4:00 PM. I'm not sure what I'm doing wrong.
EDIT: Is there a way to detect the user's current timezone? I already tried django-easy-timezones, but for some reason that doesn't work.