1
class Record(ndb.Model):
notes = ndb.TextProperty()
last_updated = ndb.DateTimeProperty(auto_now=True)
record2 = Record()
# trying to set the last_updated timestamp to a previous date
record2.last_updated = previous_date
record2.put()
#after saving it, the timestamp is back to today's date
因此,我不能效仿我的单元测试的旧纪录。如何覆盖该字段而不必更改模型?
来自docs - '可以用auto_now_add = True覆盖属性的值,但不能为auto_now = True的属性覆盖值。直到写入实体才会生成自动值;也就是说,这些选项不提供动态默认值。 (这些细节与旧的db API不同。)'你可能不得不在设置测试的同时摆弄模型。 –
@蒂姆霍夫曼为什么不把它作为回答而不是评论? – Lipis
我经常这样做,当我不满意它作为答案:-) –