如何灵活地将 schema.Datetime 字段设置为 None
我正在用 Dexterity 编写一个简单的内容类型来管理客户,除了常用字段,例如姓名、公司、电话...... 我还添加了一个日期时间字段来存储第一次会议的时间 客户已经举行,我们称之为“第一次会议”,这是我定义的 在我的界面 ICustomers 中为:
firstmeeting = schema.Datetime(
title=_(u"First Meeting"),
required=False,
)
现在,我注意到当我保存新的客户文档时,第一次会议 即使我没有设置任何日期,字段也已填充当前日期 形式,这不是我想要的,因为没有与 客户已被保留。所以我想知道如何设置 None 值 对于该字段,因此不会显示任何内容。
我一直在尝试使用 Martin Aspeli 解释过的自定义类 http://plone.org/products/dexterity/documentation/manual /开发人员手册/高级/类 但我不知道如何检查用户输入并设置 None 值(如果没有) 已输入。
谢谢
I'm writing a simple content type with Dexterity to manage customers, beside the usuals fields, eg name, company, phone...
I've also added a Datetime field to store when the first meeting with
customers has been held, lets call it 'firstmeeting', which I defined
in my interface ICustomers as:
firstmeeting = schema.Datetime(
title=_(u"First Meeting"),
required=False,
)
Now, I notice that when I saved a new Customer document the firstmeeting
field has been filled with the current date even if I don't set any date
in the form, which is not what I want because no meeting with the
customer has been held yet. So I'd like to know how to set a None value
for this field so nothing will be displayed.
I've been trying to use a custom class has explained by Martin Aspeli in
http://plone.org/products/dexterity/documentation/manual/developer-manual/advanced/classes
but I don't know how to check the user input and set None value if nothing
was typed in.
Thanks
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
您尝试过
default=None
吗?Have you tried
default=None
?我发现我的代码中发生了什么。
实际上问题出在模板 view.pt 中,我在其中使用了 toLocalizedTime() 函数,
它将 None 值转换为当前日期,因此我添加了 tal:condition 来打印日期值。
I found out what was happening in my code.
Actually the problem was in the template view.pt where I used toLocalizedTime() function,
which was converting the None value to the current date, so I added a tal:condition to print the date value.