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

Somehow I can't define a local class variable that I can read and write to in multiple methods.


class Queue(models.Model):
​myVar = {}

​def method(self):
​​ ​self.myVar = {"var":"value"}


Error:

ValueError: : "'module.model' object attribute 'var' is read-only" while evaluating


How would this be approached in Odoo? 

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

Hi

perhaps you can try to access from class level using dot notation.

Therefore, the solution might be close to :

Queue.myVar = {"var":"value"}

Queue is the class and myVar is part of the Queue class.

Or, if it still unable to access it you need to identify the upper level like the module name or the file name like

​YourModule.YourFile.Queue.myVar = {"var":"value"}

Best regards,

Altela (altelasoftware.com)

Ảnh đại diện
Huỷ bỏ
Bài viết liên quan Trả lời Lượt xem Hoạt động
3
thg 2 16
5694
1
thg 3 15
11050
1
thg 3 15
5297
2
thg 5 25
1114
0
thg 3 25
1375