跳至內容
選單
此問題已被標幟
2 回覆
18503 瀏覽次數

It is possible to access the string of the field?

Example:

privacy = fields.Selection([('y', _("Yes")), ('n', _("No"))], string=_("Generic Privacy")

I want "Generic Privacy"



Thanks in advance



頭像
捨棄

Hi,

You will get field string by adding this in your python code

self._fields['field_name'].string

or  

self.env['model']._fields['field_name'].string

Thanks

you can use the string attribute of the field:

field_string = self.env['your.model'].fields_get(['privacy'])['privacy']['string']

In the above code, replace 'your.model' with the actual model name where the privacy field is defined. The fields_get method returns a dictionary of field definitions, and you can access the string value of the privacy field from the dictionary.

Now, the field_string variable will contain the string value "Generic Privacy" as defined in the field declaration.

最佳答案

I used the same way to get the field name in qweb pdf reports like this:

 
style=" margin-inline-end: 20px;">t-esc="doc._fields['movement'].string" />

however when I translated the module the field string value remained in the original language

do you have any idea how can I get the translated string value of a field?

頭像
捨棄

use t-field instead of t-esc, just t-field="doc.field_name"

I don't want the field value I want the field name in this case "string attribute"

最佳答案

please how can i get the field value 

頭像
捨棄
相關帖文 回覆 瀏覽次數 活動
1
12月 22
4739
1
6月 19
4785
0
3月 24
885
3
2月 24
4191
1
8月 22
2121