How can I set a schema.Datetime field to None with Dexterity
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/dexter开发者_StackOverflow中文版ity/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
Have you tried default=None
?
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.
<span id="form-widgets-firstmeeting" class="datetime-widget datetime-field"
tal:condition="context/firstmeeting"
tal:content="python:context.toLocalizedTime(context.firstmeeting)" />
精彩评论