I did this with behavior adapting to INameFromTitle
in behaviors.py
class INameFromBrandAndModel(Interface): """ Interface to adapt to INameFromTitle """ class NameFromBrandAndModel(object): """ Adapter to INameFromTitle """ implements(INameFromTitle) adapts(INameFromBrandAndModel) def __init__(self, context): pass def __new__(cls, context): brand = context.brand model = context.modeltype title = u'%s %s' % (brand,model) inst = super(NameFromBrandAndModel, cls).__new__(cls) inst.title = title context.setTitle(title) return inst
in behaviors.zcml or configure.zcml
<plone:behavior title="Name from brand and model" description="generates a name from brand and model attributes" for="plone.dexterity.interfaces.IDexterityContent" provides=".behavios.INameFromBrandAndModel" /> <adapter factory=".behaviors.NameFromBrandAndModel" />
Then disable the INameFromTitle behavior in profiles/types/your.contenttype.xml .
Voila. It integrates very well and shows the correct title in the default view and navigation. Removing context.setTitle(title) from the adapter will simply leave us with the correct identifier, but the title will not be set.
This will not change the name automatically after editing. So far I have not had time to override the klass property for my content types, as is often suggested.
If you define the title attribute in your schema, for example:
class IBike(form.Schema): """A bike """ title = schema.TextLine( title = _(u'Title'), required = False, )
You can easily change the name later. Hide the header field in addForm should be done to avoid misunderstandings.
ansi_lumen
source share