Proteus: Setting Lines attribute to a Model

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?

proteus is designed to mimic the other clients. So you can do mainly only what can be done from these clients.
So to add record to a One2Many field, you must add them one by one using .append() or .new().

So can’t I make a ModelList of purchase lines and add them all together?
model.lines = model_list can work, can it not?

How does such behavior is possible in the clients?

Certainly it is possible using the extend method.

This topic was automatically closed 30 days after the last reply. New replies are no longer allowed.