我有一个奇怪的问题,就是使用Mariadb在Django DateTimeField
中保存1.8
。
我有一个面纱:
print 'going to update lastposted', topic.lastposted
topic.lastposted = timezone.now()
topic.save()
print 'new topic lastposted time', topic.lastposted
字段lastposted
在模型中定义为:
class Topic(models.Model):
#other fields
lastposted = models.DateTimeField(blank=True)
def save(self, *args, **kwargs):
if not self.id and not self.slug:
slug = slugify(self.title)
slug_exists = True
counter = 1
self.slug = slug
while slug_exists:
slug_exits = Topic.objects.filter(slug=slug).exists()
if slug_exits:
slug = self.slug + '_' + str(counter)
counter += 1
else:
self.slug = slug
break
super(Topic, self).save(*args, **kwargs)
当我在主题中添加新帖子时,我会在终端中看到:
going to update lastposted 2018-06-25 03:45:11+00:00
new topic lastposted time 2018-06-25 15:12:08.469940+00:00
但是当我在数据库数据库phpMyAdmin中看到该字段时,它仍然具有相同的旧值,即2018-06-25 03:45:11
。
奇怪的是,有时更新会发生。
这可能是什么问题?我该如何解决?
答案 0 :(得分:0)
尝试
super(Topic, self).save(args, kwargs)
两次使用*会导致错误。