Hi guys
I've built a selection that gets all the modelnames from the database:
model_names = fields.Many2one('ir.model', 'Model to use')
This builds a selection where the user can see all models and choose one out. The next step that I want is that when the user selects a model from the selection that the next field (a Many2Many) is automaticly getting all fields that are in the model the user selects.
For example: the user chooses res.partner from the model_names selection. The next field (Many2Many) should now show all fields that are available in the res.partner model.
How exactly should I do this? I should access the model ir.model.fields and get every single field that matches the correct model the user selected. I assume I should create an onchange that loads all fieldnames in the Many2Many when the user selected something in the Many2one? Would this also be possible with a domain_filter?
XML file:
<record model="ir.ui.view" id="my_form_view">
<field name="name">myname.form</field>
<field name="model">model.builder</field>
<field name="arch" type="xml">
<form string="My Form">
<sheet string="test">
<group>
<field name="name"/>
<field name="model_names"/>
<field name="fields_to_use"/>
</group>
<notebook>
<page string="Advanced" name="Advanced">
</page>
</notebook>
</sheet>
</form>
</field>
</record>
Python code:
from openerp import models, fields, api
class MyClass(models.Model):
_name = 'model.builder'name = fields.Char(string="Title", required=True)
model_names = fields.Many2one('ir.model', 'Model to use', help='The model that you use here will give you access to all fields from this model. This will auto-generate the fields in the next dropdown.', required=True)
fields_to_use = fields.Many2many('ir.model.fields', 'field_names_model', required=True)@api.one
@api.depends(
'model_names',
'model_names.field_id',
'model_names.field_id.model_id',
)
def _get_names(self):
self.fields_to_use_computed = self.model_names.field_id.filtered(lambda l: l.model_id.id == self.model_names.id)fields_to_use_computed = fields.Many2many('ir.model.fields', compute='_get_names', string='Fields to use COMPUTED')
@api.onchange('fields_to_use_computed')
def do_stuff(self):
self.fields_to_use=self.fields_to_use_computed
I'd love some help as I have no clue here.
Thanks
Yenthe
Settings/Database Structure is not similar?
When you open up a specific module and get all the field names yes.. But I would like to get all those fields from a specific model in a Many2Many so the user can select the fields from the specific model he chose in the previous selection.