コンテンツへスキップ
メニュー
この質問にフラグが付けられました
2 返信
4653 ビュー

Ex.

class myClass(models.Model):
_name = 'my.class'
name = fields.Char(string='Title', required=True)
description = fields.Char(string='description', required=True)
model_name = fields.Many2one('ir.model', string="Model", required=True)
model_field = fields.Many2one('ir.model.fields', string='Field', domain="[('model_id', '=',model_name))

How i get date strings from M2O fields:  model_name, model_field.

Let says, in a @api.onchange decorator, thanks in advance.

@api.depends('time', 'model_field')
@api.onchange('model_field')
def _my_funt(self):
    code...
アバター
破棄
著作者 最善の回答

Hi, this is my code:

class myClass(models.Model):
_name = 'my.class'

name = fields.Char(string='Title', required=True)
description = fields.Char(string='description', required=True)
model_name = fields.Many2one('ir.model', string="Model", required=True)
model_field = fields.Many2one('ir.model.fields', string='Field', domain="[('model_id', '=',model_name),('ttype', 'in', ['datetime','date'])]", required=True)
    date_set = fields.Date(string='Select Date')
    date_from = fields.Date(string="Start Date")
    date_to = fields.Date(string="End Date")
    time = fields.Integer("Value")
    time_left = fields.Char(compute="_calcule")

@api.onchange('model_field')
    def _calcule(self):
        self.time_left = self.model_name.model_field


i tried:

self.time_left = self.model_name.model_field

 But it showing a error:

AttributeError: 'ir.model' object has no attribute 'model_field'

thanks

アバター
破棄
著作者

Hi, DHA Medic model_field is the name of de the many2one field in my.class

I would like to understand, how i can access the value from this field, that in this case is a date.

Im just getting the record(xxxx,) instead the value of that record.

Thanks

@api.onchange('model_field')

def _calcule(self):

if self.model_field:

mid = self.model_field.id

self.time_left = self.env['ir.model'].search([('field_id', '=', mid)])

#you must debug this code, i have not test it

pastebin.com/i20zDMDL

著作者

I have tested it.

Im getting ir.model(317,) on time_left field.

Thanks

最善の回答

self.model_name.your_field_want_to_get

アバター
破棄
関連投稿 返信 ビュー 活動
2
3月 24
1751
1
4月 16
3353
3
10月 15
11867
2
2月 25
8726
1
4月 24
1788