Skip to Content
Menu
This question has been flagged
1 Reply
1118 Views
Hello  how  do  i  update  a   releated fields globaly?

exemple: i have 2 classes 

"class  participant
   "_name = 'participant'
    "name=Field.Char("Name")

    "phone=Field.Char("Phone")

#and     

"class  activity
   "_name = 'activity'
    "name=Field.Date("Date")

    "participant=Field.Many2one("participant",  "Participant")

     "phone=Field.Char("Phone",  related="participant.phone")


Now i want  when  i  put  a new  value  on  activity.phone,  this  new  value  should  automaticaly update  the  participant.phone one .


Thanks  



Avatar
Discard
Best Answer

If two models have a field which are 1 to 1, use the related attribute in field definition.

class Participant(models.Model):
    _name = 'participant'
phone = fields.Char('Phone')

class Activity(models.Model):
_name = 'activity'
participant_id = fields.Many2one('participant', string='Participant')
phone = fields.Char('Phone', related='participant_id.phone', readonly=False)
Avatar
Discard
Author

Hello, i think this is what i try in m'y first post 'the related solution'

But this is ok in one Way, eg: in activity forms when Select a participant , the phone IS auto-complete this is the right Way.

But when you update the phone , in this forms, or create a New one if not existent, this last data could be found or updated in participant table. How to correct that?

I have difficulties understanding your question.
I assume you are trying to modify the field 'phone' on both models of 'participant' and 'activity'
By default a 'related' attribute means, 1. not stored, 2. not copied, 3. readonly, 4. computed in superuser mode
make it be like
phone = fields.Char('Phone', related='participant_id.phone', readonly=False)
This way you can edit the field phone on both model.

Related Posts Replies Views Activity
1
Nov 24
1486
1
Nov 24
1195
2
Sep 24
1047
1
Aug 24
2456
3
Aug 24
2687