【发布时间】:2016-09-07 11:46:31
【问题描述】:
我使用 Python Dexterity Type 编写产品,我有一个字段 shema.Datetime(见下文),我想在 Plone 中创建表单时设置一个默认日期时间。
我尝试使用 Zope DateTime 和 Python DateTime,但不起作用。 在docs zope schema 中没有这方面的示例。
# 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,
)
那么,在这种情况下我如何设置默认值?
【问题讨论】:
-
尝试使用
DateTimeNow = datetime.datetime.now,不带括号。 -
@turkus 所说的,或者换句话说,传递它一个(工厂)可调用产生一个值而不是值。来自plone docs:“defaultFactory 是一个函数,将在加载添加表单时调用以确定默认值。”
-
@turkus 我试过我的输出是
TypeError: Error when calling the metaclass bases unhashable type: 'list' > /home/jafar/training/buildout/eggs/zope.interface-3.6.7-py2.7-linux-x86_64.egg/zope/interface/interface.py(415)get() -
这个错误是否与 DateTimeNow 一致?我认为这个错误是关于其他的。
-
@turkus 如果我选择
DateTime()或DateTime().asdatetime()或datetime.datetime.now()或datetime.datetime.now或DateTime().asdatetime输出错误是不同的......我认为它属于。如果看到错误显示type: list,那么问题来了,schemaDatetime .. defaultFactory接受什么类型?在 Zope Doc 中说:represented as a a Python datetime.DateTime.so... 我设置但不工作。我可以将所有代码发布给您,如果您愿意的话。我找到了这个docs.plone.org/4/en/external/plone.app.dexterity/docs/advanced/…,而且也不行。
标签: python datetime zope dexterity