Reputation: 340
I have the table: Employees, which contains only the field 'name' and 'login' (it's associated to the table users)
class Employees(osv.osv):
_name = 'Employees.Employees'
_columns = {
'the_name':fields.char('Name:', size = 50),
'user_id': fields.many2one('res.users', 'User:', select = True),
}
Employees()
Example:
'John' -> '[email protected]'
'Marilyn' -> '[email protected]'
Then I have the table: Tasks, which contains the fields 'name', 'description', and 'employees_id'. When a task is created it could contain several employees for the same task, that's why I choose the "many2many" because I could select several employees. So, I have tried the following:
class tasks(osv.osv):
_name = 'tasks.tasks'
_columns = {
'the_name':fields.char('Name', size = 50),
'description':fields.text('Description'),
'employees_id':fields.many2many('Employees.Employees', 'Employees', '???', 'user_id', 'All Employees')
}
tasks()
Example:
'Carry sand' -> 'Carry the whole sand from the beach' -> '[email protected]; [email protected]'
'Play' -> 'Play with legos' -> '[email protected]'
But I don't know what to put on "???"..thanks.
Upvotes: 0
Views: 5790
Reputation: 41
You have to add the third Field Like :-
'employees_id': fields.many2many('Employees.Employees',
'tasks_employees_rel',
'employee_id',
'task_id',
'All Employees')
for Employee...
it will create another table which contains the fields 'employee_id', 'task_id',
you can easily retrieve these values by just looping on this that is
task_obj.employees_id: it will return List of employees associated with underline ta
Upvotes: 0
Reputation: 3207
fields.many2many('other.object.name', 'relation object', 'actual.object.id', 'other.object.id', 'Field Name')
Example
'category_ids':
fields.many2many(
'res.partner.category',
'res_partner_category_rel',
'partner_id',
'category_id',
'Categories'),
'employees_id':fields.many2many('employee.employee', 'employee_user_rel', 'user_id', 'employee_id', 'All Employees')
}
Hope this help
Upvotes: 4