Skip to Content
Menu
This question has been flagged
1 Reply
12694 Views

Hi guys Help me I want to fill the many2many filled automaticly withou have to click on the add button

image description

I want fo fill the mannu "Lista de Pets" with the records on the "pets" when I click on the "Lista de Pets"

It is possible?

Show me an example please

Avatar
Discard
Best Answer

If you just want to view a list of all the pets, I recommend a wizard (osv.osv_memory).

Anyway, wizard or not:
Add a default value for your many2many field and use a function to get all pets.

_columns = {
    'pet_ids' = fields.many2many(.....),
}

def _get_default_pet_ids(self, cr, uid, context=None):
    return self.pool.get('your_pet_module').search(cr, uid, [])

_defaults = {
    'pet_ids' = _get_default_pet_ids,
}

That's it.

EDIT:

The standard way to filter your data is using a search view.
But if you want to use a selection field do something like this:

def onchange_onwer_id(self, cr, uid, ids, val):
    ids = self.pool.get('your_pet_module').search(cr, uid, [('owner_id','=',val)])
    return {'value' : {'pet_ids' : ids}} 

_columns = {
    'pet_ids' = fields.many2many(.....),
    'owner_id' = fields.many2one(.......),
}

and in your .xml:

<field name="owner_id" on_change="onchange_owner_id(owner_id)"/>
Avatar
Discard
Author

thank you very much man. And if I want to put a selection filed to filter the records how can I do it?

Author

I have the 'owner_id' many2one filed I want to filter the pets by owner

Author

another question if u could help me... I want to put checkbox into the rows and when it are check load buttons to delete the records from the database. like in tree view when you check the checkbox, pops up a button and we can delete the records. I want the same and with the same button if its possible

I guess I don't know the answer to this question. Try removing the widget on your many to many field, or something. ^^

Author

ok thanks a lot you helped very much :)

Author

If I want to remove the 2 first rows on the many2many field by clicking on a button ("Remove") wich function I have to do? (btw you have to put here your email or skype eheh I have some questions and you help a lot)

Author

could you help me in another problem? hehe pls go to my question "many2many button action" if you know it pls explain me :)

Great sample :) It missed a : at the function so I corrected that. Thanks René

Related Posts Replies Views Activity
1
Jul 18
2573
0
Jan 16
2526
1
Mar 15
3836
0
Mar 15
6341
0
Jul 22
1372