I am building a BlogApp AND i am stuck on a Problem.
What i am trying to do :-
I am trying to store timezone in every field ( post date, comment date ) according to User's Country
.
Suppose, A user is registered account on webapp from
Brazil
then i am trying to automatically set time zone of Brazil for theUser
.
But i have tried many answers LIKE THIS and LIKE THIS but nothing worked for me. Some told that it should be done through JavaScript
BUT i have no idea idea how can i do it.
When i try to register then it automatically sets the timezone
which i have settled in settings.py
.
TIME_ZONE = 'UTC'
What have i tried :-
- I have also tried localize ( according to docs ) BUT still showing the same time.
models.py
class Post(models.Model):
post_owner = models.ForeignKey(User,default='',null=True,on_delete = models.CASCADE)
date_added = models.DateTimeField(null=True,default=timezone.now)
settings.py
TIME_ZONE = 'UTC'
USE_I18N = True
USE_L10N = True
USE_TZ = True
new_post.html
{% load l10n %}
{% localize on %}
{{ form.date_added|as_crispy_field }}
{% endlocalize %}
all_posts.html
{% load l10n %}
{% localize on %}
{{ post.date_added|as_crispy_field }}
{% endlocalize %}
I have set
UTC
in settings BUT i am inAsia/Kolkata
timezone. So it should localize thetimezone
into my Local Time. BUT it is still inUTC
.
Any help would be appreciated.
Thankyou in advance.