Skip to Content
Menu
Musisz się zarejestrować, aby móc wchodzić w interakcje z tą społecznością.
To pytanie dostało ostrzeżenie
3 Odpowiedzi
7686 Widoki

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

No errors but it does not work.

Awatar
Odrzuć
Najlepsza odpowiedź

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

Awatar
Odrzuć
Autor

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

Najlepsza odpowiedź

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

Awatar
Odrzuć
Powiązane posty Odpowiedzi Widoki Czynność
0
lut 25
1656
0
sty 25
1407
1
gru 24
1832
1
gru 23
1648
1
cze 22
6022