Skip to Content
Menu
This question has been flagged
3 Replies
1959 Views

hello, i'ld like to use Many2one relation to get value from other model but i don't want it to take all the informations of the model (table) 

eg: attribute of model.personne are: id, name, surname, gender, birthday. 

How Many2one relation can return only male (or female) personne?  

name = fields.Many2one('model.personne', 'presonne') # i want to select between gender=male personne 

Avatar
Discard
Best Answer

You need to put domain  in many2one fields for show only that records which is male. 

domain=[('gender', '=', 'male')]
Avatar
Discard
Best Answer

Hi,

If you are looking to get the value from the model.personne in your model, from the above code it seems you have  got a Many2one relation to that model, so using this model you can access the rest of the values in that model/record.

See this sample:

class ModelPersonne(models.Model):
_name = 'model.personne'

gender = fields.Selection([
('male', "Male"),
('female', "Female"),
], default='male', string='Options')


class NewMode(models.Model):
_name = 'new.model'

personne_id = fields.Many2one('model.personne', 'presonne')
option = fields.Selection([
('male', "Male"),
('female', "Female"),
], default='male', string='Options', related='personne_id.gender')


Thanks

Avatar
Discard
Author

thanks! but this not exatly what i want to do.

we have normal use of Many2one relation like yhis

personne_id = fields.Many2one('model.personne', 'presonne') # that mean i can select any object in model.personne in order to assign it to personne_id

NOW WHAT I WANT IS:

male_personne_id = fields.Many2one('model.personne', 'presonne') # how is the correct form of code for having to select only between object whitch gender attribute is "male"?