Bỏ qua để đến Nội dung
Menu
Câu hỏi này đã bị gắn cờ
1 Trả lời
37753 Lượt xem

I'm creating a record through a RPC call and want to calculate some fields on the model using the option store=True,  my question is: 


If I use the store=True option the field it's computed everytime i open that record or just the first time? 


Can't find a clear explanation about that in the documentation, hope you can help my about this.

Regards



Ảnh đại diện
Huỷ bỏ
Câu trả lời hay nhất

Whether stored or not stored, computed fields have a compute method. The annotation on the compute method specifies when the re-calculation should run, depending on if it's stored or not.

For example (stored):

@api.depends('name', 'surname')
def compute_display_name(self):
# This will be called every time the name or surname field changes
pass

display_name = fields.Char(compute=compute_display_name, store=True)

For example (not stored):

def compute_display_name(self):
# This will be called every time the field is viewed
pass

display_name = fields.Char(compute=compute_display_name, store=False)
Ảnh đại diện
Huỷ bỏ
Tác giả

Thanks for your answer

you should make sure if the function will be invoked if the flag store=true with the decorator depends. Just check

Bài viết liên quan Trả lời Lượt xem Hoạt động
1
thg 5 23
2343
3
thg 5 23
17245
2
thg 7 22
6989
1
thg 9 21
14093
3
thg 2 24
18136