Personal tools
Home Webmaster Resources Zope/Plone Prefill Archetype fields

Prefill Archetype fields

Archetypes gives you the ability to specify a static default value for a field.  It gets a bit more complex when you need to specify a dynamic default value, such as a value from the ZODB.

The following code from the Archetype schema definition file should give you a good start.  The default_method is the attribute of choice here:


schema = copybase + Schema((
    StringField('company',
                required=1,
                default_method='getMemberCompany',
        widget=StringWidget(
            label="Company/Organization",
            ),
        ),

...


class productName(BaseContent):

    schema = schema

    def getMemberCompany(self):
      return getattr(self.portal_membership.getAuthenticatedMember(), 'company')

Need assistance with your project? Universal Web Services can help.
Contact us to request a quote.