为什么当我更新数据库中的条目时更新了模型中的更新时间字段
updated = models.DateTimeField(auto_now=True)
根据我的设置文件中的时区正确更新,但是当它出现在Django rest Framework终端中时,它会向后移3个小时
以下代码适用于模型:
class hashtag(models.Model):
tag = models.CharField(max_length=120)
count = models.IntegerField(default=0,blank=True)
timestamp = models.DateTimeField(auto_now_add=True)
updated = models.DateTimeField(auto_now=True)
以下代码用于DRF:
last_update = serializers.SerializerMethodField()
class Meta:
model = hashtag
fields = [
'id','tag','date_display','last_update','timestamp','updated'
]
def get_last_update(self,obj):
return obj.updated.strftime('%b %d %I:%M %p')