(Django - Python) timedelta 保存形式的问题

(Django - Python) Problems with timedelta saving form

我的拍卖网站有问题,因为当我发布拍卖时,函数没有正确保存我的变量,这些是我的代码:

发布已正确完成,除 endDate 之外的所有内容始终等于 startDate...

我也尝试过使用 datetime.datetime.now 而不是 auction.startDate 或 datetime.timedelta(days=1) 但是当我得到 shell 中的值时总是一样的...

在 scratch.py 文件中我写了相同的代码并且它有效,我不知道为什么在函数中不起作用... :S

谢谢大家!

您已在 endDate 字段上定义了 auto_now_add=True,这使得字段不可编辑并设置为 now()。来自 documentation:

Automatically set the field to now when the object is first created. Useful for creation of timestamps. Note that the current date is always used; it’s not just a default value that you can override. So even if you set a value for this field when creating the object, it will be ignored.