I'm using Django 1.11 and pytz==2018.3.
I have a chat model with a timezone field that won't display in local time.
class Message(models.Model):
sender = models.ForeignKey(User, on_delete=models.CASCADE, related_name='sender')
receiver = models.ForeignKey(User, on_delete=models.CASCADE, related_name='receiver')
message = models.CharField(max_length=1200)
timestamp = models.DateTimeField(auto_now_add=True)
is_read = models.BooleanField(default=False)
When I print it normally like this I get:
<div class="textcontainer lighter">
{{ message }}
<span class="time-right">{{ message.timestamp|date:"SHORT_DATETIME_FORMAT" }}</span>
</div>
output:
July 8, 2018, 2:55 a.m
However, this is UTC time (6 hours ahead. I want it to say a different time instead).
I've tried the following:
{{ message.timestamp|localtime }}
But this doesn't do anything.
I've also tried including these two as well:
{% load tz %}
{% get_current_timezone as TIME_ZONE %}
In my settings.py file I have:
USE_L10N = True
USE_TZ = True
Thoughts? Thanks in advance!