Skip ke Konten
Menu
Pertanyaan ini telah diberikan tanda
3 Replies
7382 Tampilan

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

No errors but it does not work.

Avatar
Buang
Jawaban Terbai

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"/>

Avatar
Buang
Penulis

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)]})

Jawaban Terbai

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"/>

Avatar
Buang
Post Terkait Replies Tampilan Aktivitas
0
Feb 25
1313
0
Jan 25
1137
1
Des 24
1462
1
Des 23
1489
1
Jun 22
5599