我有一个灵活的自定义类型(模式驱动),没有标题或描述字段。
class IAnimal(model.Schema):
name = schema.TextLine(title=_(u"Name"),required=True,)
specie = schema.Choice(title=_(u"Specie"),vocabulary=animalSpecies)
weight = schema.TextLine(title=_(u"Weight"))
(etc)
我的模型确实不需要标题字段,但是当我创建一些内容时,文件夹列表显示:
— by admin — last modified Oct 17, 2015 02:27 PM
我用 mr.bob 创建了这个产品并且还没有覆盖任何表单。这可以通过覆盖任何形式、自定义行为(如 plone.app.content.interfaces.INameFromTitle)或什么来实现?
我只想将“名称”字段作为“标题”而不更改“名称”作为“标题”,即使我必须在模型中隐藏“标题”字段也是如此。
看一些老原型(prototype)产品,是这样的方法:
def at_post_create_script(self):
title = self.name
plone_utils = getToolByName(self, 'plone_utils', None)
new_id = plone_utils.normalizeString(title)
self.setTitle(new_id)
请您参考如下方法:
我不明白为什么你不能简单地提供一个名为“名称”的“标题”字段(最简单的方法),但是你也可以覆盖 title 属性和 Title 基类的方法。
如果您使用 mr.bob,您可能没有可以自定义的基类。 检查您的类型定义 XML:在 klass 属性中您可能有 plone.dexterity.content.Item。将其更改为您必须添加到产品中的新的灵 active 基类(例如:https://github.com/collective/wildcard.media/blob/84b82994dc424fe40b92b1c9af8d48edb558a78d/wildcard/media/content.py#L6)
当您拥有基类时,您可以添加 Title 方法和 title 属性,例如:
class MyType(Item):
implements(IMyType)
def Title(self):
return self.name
@property
def title(self)
return self.name
