Skip to Content
เมนู
คุณต้องลงทะเบียนเพื่อโต้ตอบกับคอมมูนิตี้
คำถามนี้ถูกตั้งค่าสถานะ
1 ตอบกลับ
3361 มุมมอง

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? 

อวตาร
ละทิ้ง
คำตอบที่ดีที่สุด

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)

อวตาร
ละทิ้ง
Related Posts ตอบกลับ มุมมอง กิจกรรม
3
ก.พ. 16
5695
1
มี.ค. 15
11052
Instantiation of python classes? แก้ไขแล้ว
1
มี.ค. 15
5298
2
พ.ค. 25
1114
0
มี.ค. 25
1375