I codding a product using Python Dexterity Type, and I have one field shema.Datetime (see below), And I want set a default date time when form was create in Plone.
I tried using Zope DateTime and Python DateTime, and don't work. In docs zope schema don't have examples for this.
# I'm tried use this options with DateTime
from DateTime import DateTime
# DateTimeNow = DateTime()
# DateTimeNow = DateTime().asdatetime()
# And tried use datetime
import datetime
DateTimeNow = datetime.datetime.now()
class IDigitalFile(model.Schema):
...
uploded_at = schema.Datetime(
title=_(u"Data de Upload"),
required=True,
defaultFactory=DateTimeNow,
)
So, How I set default value in this case?
The solution is using Python Datetime, and not Zope DateTime, see code:
from datetime import datetime
...
def nowDateTime():
return datetime.today()
...
directives.mode(uploded_at="hidden")
uploded_at = schema.Datetime(
title=_(u"Data de Upload"),
required=True,
defaultFactory=nowDateTime,
)