I have a custom type in dexterity (schema driven) without title or description fields.
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)
I really don't need the title field on my model, but when I create some content, on folder listing is displaying:
— by admin — last modified Oct 17, 2015 02:27 PM
I created this product with mr.bob and didn't override any forms yet. This can be accomplished by override any forms, a custom behavior (like plone.app.content.interfaces.INameFromTitle) or what?
I just want the "name" field as "title" without changing "name" for "title", even that I must have to hide the "title" field in the model.
Looking at some old archetypes products, it was a method like:
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)
I didn't get why you can't simply provide a "title" field named "Name" (easiest way), however you can also override the title
attribute and Title
method of the base class.
If you used mr.bob you probably don't have a base class you can customize.
Check your type definition XML: in the klass
property you probably have plone.dexterity.content.Item
. Change it to a new dexterity base class you must add to you product (example: https://github.com/collective/wildcard.media/blob/84b82994dc424fe40b92b1c9af8d48edb558a78d/wildcard/media/content.py#L6)
When you have the base class you can add the Title
method and a title
attribute, something like:
class MyType(Item):
implements(IMyType)
def Title(self):
return self.name
@property
def title(self)
return self.name