def test_post_order_positioning_by_date(self):
Post.objects.create(
body="test",
date_added="2020-12-31 18:51:19.959463+01:00",
author=self.user,
uniqueID="61672dba-0d36-43b1-b36a-bbd0a3d317b5",
image=""
)
post = Post.objects.get(uniqueID="61672dba-0d36-43b1-b36a-bbd0a3d317b5")
print(post.date_added)
This function when printig post.date_added show code below:
2020-12-31 17:51:19.959463+00:00
Here is the model code:
class Post(models.Model):
author = models.ForeignKey(settings.AUTH_USER_MODEL, on_delete=models.CASCADE, related_name='author')
body = models.TextField(max_length=500, default="")
date_added = models.DateTimeField(auto_now_add=False)
image = models.ImageField(default=None, upload_to="posts/")
uniqueID = models.UUIDField(unique=True, max_length=255, primary_key=True)
def __str__(self):
return str(self.uniqueID)
def pre_save_post_receiver(sender, instance, **kwargs):
print(sender, instance)
pre_save.connect(pre_save_post_receiver, sender=Post)
Any idea why this happens? I tried overide_settings and changins timezone for this function and django module timezone with timezone.localtime(timezone.now()) but both of these attempts failed.