تخطي للذهاب إلى المحتوى
القائمة
لقد تم الإبلاغ عن هذا السؤال
3 الردود
7218 أدوات العرض

How to set an attribute of a field like this self._fields['name'].readonly=True ?

No errors but it does not work.

الصورة الرمزية
إهمال
أفضل إجابة

Do you wish to make the field readonly? In this case you either define it on the just created field (something like: your_field = fields.Char(string='My string', readonly=True)

or in XML by doing this:

<field name="your_field" readonly="1"/>

الصورة الرمزية
إهمال
الكاتب

I need to be able to write into a field and later on some conditions make the field readonly. As I know it can be done with 'state' field in this way:

my_field=field.Char(readonly=True, states={'draft': [('readonly', False)]})

أفضل إجابة

Set the readonly in python code, like this:
my_field = fields.Char(readonly=True)


or in a xml, like this:
<field name="my_field" readonly="1"/>

الصورة الرمزية
إهمال
المنشورات ذات الصلة الردود أدوات العرض النشاط
0
فبراير 25
1249
0
يناير 25
1085
1
ديسمبر 24
1376
1
ديسمبر 23
1430
1
يونيو 22
5504