Commit cc988a2f authored by Administrator's avatar Administrator
Browse files

fixed issue of timezone.now()

parent 5ac71371
...@@ -6,6 +6,7 @@ ...@@ -6,6 +6,7 @@
# * Remove `managed = False` lines if you wish to allow Django to create, modify, and delete the table # * Remove `managed = False` lines if you wish to allow Django to create, modify, and delete the table
# Feel free to rename the models, but don't rename db_table values or field names. # Feel free to rename the models, but don't rename db_table values or field names.
from django.db import models from django.db import models
from django.utils import timezone
class DemoUsers(models.Model): class DemoUsers(models.Model):
...@@ -34,7 +35,7 @@ class DemoUsers(models.Model): ...@@ -34,7 +35,7 @@ class DemoUsers(models.Model):
# 检查对象是否存在数据库中,即判断是否有主键pk # 检查对象是否存在数据库中,即判断是否有主键pk
if self.pk: # 对象已存在,表示是更新操作 if self.pk: # 对象已存在,表示是更新操作
# 在这里执行你希望在更新时发生的自动赋值逻辑 # 在这里执行你希望在更新时发生的自动赋值逻辑
self.last_update_date = now() # 你的自定义更新逻辑 self.last_update_date = timezone.now() # 你的自定义更新逻辑
else: else:
self.creation_date = new() self.creation_date = timezone.now()
super().save(*args, **kwargs) # 调用父类的save方法完成保存 super().save(*args, **kwargs) # 调用父类的save方法完成保存
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment