Suppose I have an instance of a model, say, purchase.purchase. It is assigned to a variable (let’s call it model) so that
>>> model
proteus.Model.get('purchase.purchase')(-44)
Now I want to add purchase lines to it, and I have a list of lines such that
>>> model_lines
[proteus.Model.get('purchase.line')(-25),
proteus.Model.get('purchase.line')(-26),
proteus.Model.get('purchase.line')(-27)]
What’s the best way of setting the lines attribute of model as model_lines?
NOTE: I don’t want to use lines explicitly, such as in model.lines.append() or model.lines.new(), because the model could be anything (for example model could be of type party.party and model_lines could be of type party.addresses.
So, I would prefer something like: setattr( model, 'lines' , model_list)
But this raises AttributeError.
Any ideas?
EDIT: I believe that model_list needs to be of type ModelList, whereas mine is just a plain python list. So I guess my question boils down to: how do I make a ModelList out of my python list?