当我进入shell时,我遇到了以下问题:
from users.models import Status
from django.utils import timezone
Status.objects.all()
>>> []
p = Status()
p.status_time = timezone.datetime.min
p.status_time
>>> datetime.datetime(1, 1, 1, 0, 0)
p.save()
Status.objects.all()
>>> [<Status: Status object>]
print(Status.objects.all()[0].status_time)
>>> None
我不明白为什么status_time
没有正确保存。我的状态模型如下:
class Status(models.Model):
status = models.CharField(max_length=200)
status_time = models.DateTimeField('date published')
def __init__(self, status = '', time=timezone.datetime.min, *args, **kwargs):
self.status = status
self.status_time = time
super(Status, self).__init__(*args, **kwargs)
有人可以解释这种行为并可能提出修复建议吗?