I have a simple behavior that just adds one field to IMyType. The field name is 'program' and the schema is at IRFAProgram. It's a behavior because some people need it and some don't.
<plone:behavior name="RFAProgram" title="RFA Program | Content field" description="Adds RFA Program field to the content type" provides="rfasite.content.behaviors.themes.IRFAProgram" /> @provider(IFormFieldProvider) class IRFAProgram(model.Schema): directives.order_before(program="IThemes.theme") directives.widget(program=RadioFieldWidget) program = schema.Choice( title="Program", values=['RFA', 'PRC'], required=True, )
I also have a large collection of objects of IMyType that I'd like to import data into that field, but the behavior was just enabled now, and none of the existing objects know about it:
>>> obj.program Traceback (most recent call last): File "<console>", line 1, in <module> AttributeError: 'RequestContainer' object has no attribute 'program'
When I create or edit an existing object by visiting the edit form in a browser, the field appears and I can set it. Once I 'save', then the object has the property.
But I have thousands of objects to import.
How can I programmatically add the behavior to existing objects, and set the property on the object?
I've messed about quite a bit with IBehaviorAssignable and tried to do
obj = IProgram(obj) but I keep getting 'Can Not Adapt'.
Can someone point me in the right direction?