python - How I set default value to zope.schema.datetime? -


i codding product using python dexterity type, , have 1 field shema.datetime (see below), , want set default date time when form create in plone.

i tried using zope datetime , python datetime, , don't work. in docs zope schema don't have examples this.

# i'm tried use options datetime datetime import datetime # datetimenow = datetime() # datetimenow = datetime().asdatetime()  # , 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 set default value in case?

the solution using python datetime, , 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, ) 

Comments

Popular posts from this blog

java - Jasper subreport showing only one entry from the JSON data source when embedded in the Title band -

serialization - Convert Any type in scala to Array[Byte] and back -

SonarQube Plugin for Jenkins does not find SonarQube Scanner executable -