I am trying to convert UTC to EST in a view and display this in a template. Currently the code seems to have no effect.
Here is the view:
from django.shortcuts import render, redirect, get_object_or_404
from .models import Article
from .models import Article Image
from .models import Article Specs
from datetime import datetime
from django.utils import timezone
from django.core.paginator import Paginator
def detail(request, article_id):
article = get_object_or_404(Article, pk=article_id)
image_all = ArticleImage.objects.all()
specs_all = ArticleSpecs.objects.all()
#
est = pytz.timezone('Pacific/Auckland')
article_release_datetime = article.releaseDate.astimezone(est)
#
datetime_now = datetime.now(timezone.utc)
datetime_now.astimezone(est)
release_countdown = article_release_datetime - datetime_now
#
(days, remainder) = divmod(release_countdown.seconds, 86400)
(hours, remainder) = divmod(remainder, 3600)
(minutes, seconds) = divmod(remainder, 60)
#
return render(request, 'articles/detail.html', {'article': article,
'image_all': image_all,
'specs_all': specs_all,
'days': days,
'hours': hours,
'datetime_now': datetime_now,
'minutes': minutes,
'seconds': seconds,
'release_countdown': release_countdown})
Here is the template::
<div class="details__countdown-wrapper">
{% if release_countdown.days <= -1 %}
<a href="{{ article.get_it_url }}" class="details__get-it-url">Get it</a>
{% else %}
<span class="detail_countdown">⏱️</span>
<span class="details__dropping">DROPPING IN:</span>
{% if days %}
{{ days }}d
{% endif %}
{% if hours %}
{{ hours }}hr
{% endif %}
{% if minutes %}
{{ minutes }}m
{% endif %}
{% if seconds %}
{{ seconds }}s
{% endif %}
(EST)
{% endif %}
</div>