Extend the schema of a standard Archetypes type (ATFolder)

I'd like to add a new field (chosenDate) to all of my Archetypes content types - which is not problem so far - but to the standard ATFolder type as well (I have plenty of them already in my site, so I'd rather not invent a new type).

Here is my method, for catalog metadata creation:

def getChosenDate(self):
    """
    Return the date which was explicitly set for usage in lists
    """
    getField = self.getField
    for name in [
        'chosenDate',
        'effectiveDate',
        ]:
        field = getField(name)
        if field:
            val = field.get(self)
            if val:
                return val
    return self.created()

I'd like the ATFolder type to have that chosenDate field as well.

How would I achieve this? Thank you!

Monkey patching

class Foo(object):

    pass

def foo(self):
    print 'foo'

Foo.some_method = foo


f = Foo()
f.some_method()

Or try archetypes.schemaextender.

1 Like

A schema extender does not allow you to introduce new methods.

-aj

@tobiasherp is talking about adding a new field, not a method. He wants to access the new field later in a method called getChosenDate. If the method should be attached to the AT content type as well, then your method can be used to achieve that.

1 Like

That's right; I need both, and my question was about the field. I use archetypes.schemaextender now, and it seems to work well.