Ir al contenido
Menú
Se marcó esta pregunta
1 Responder
13541 Vistas

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
Descartar
Mejor respuesta

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
Descartar
Autor

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

Autor

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

Autor

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. ^^

Autor

ok thanks a lot you helped very much :)

Autor

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)

Autor

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é

Publicaciones relacionadas Respuestas Vistas Actividad
1
jul 18
3360
0
ene 16
3376
1
mar 15
4586
0
mar 15
7209
0
jul 22
2213