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

Hi!

I would like to display the data retrieved from the database.

This is a example of my code:

class course(models.Model):

    cost = fields.Float( )

    @api.depends

    def _get_cost(self):

        self.cost = self.env[ 'course'].cost

##############

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

アバター
破棄
最善の回答

Hi,

Not sure with your logic, you can correct as per your use case, define the field as a compute field, then

    cost = fields.Float( string="Cost", compute='_get_cost')


Then define the compute function,

  def _get_cost(self):

        cost_rec = self.env[ 'course'].search([], limit=1)

        if cost_rec:

                self.cost = cost_rec.cost


the above code will search for the records in the model named course and return a single record. As per the logic you can add search condition in it.


Thanks

アバター
破棄
関連投稿 返信 ビュー 活動
3
10月 23
8435
1
9月 23
3188
1
5月 23
2123
2
4月 23
2637
1
3月 23
2054