, i’ve set timezone in
settings.py
settings.py
TIME_ZONE = 'Asia/Kolkata'
models.py
from django.contrib.auth.models import AbstractUser
from django.db import models
from django.utils import timezone
class User(AbstractUser):
[...]
class Post(models.Model):
poster = models.ForeignKey(User, on_delete=models.CASCADE)
content = models.TextField(max_length=500)
timestamp = models.DateTimeField(default=timezone.now)
in python shell
>>> post = Post.objects.create(poster=user,content='c1')
>>> post.save()
>>> Post.objects.all()
<QuerySet [<Post: (id: 1) poster: ganesh, content: c1, timestamp: 2020-12-01 02:35:41.861310+00:00>]>
for
timestamp
fielddate
is ok. but, the timedjango
saves is not related to my timezone.