Bỏ qua để đến Nội dung
Menu
Câu hỏi này đã bị gắn cờ
1 Trả lời
7806 Lượt xem

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

Ảnh đại diện
Huỷ bỏ
Câu trả lời hay nhất

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

Ảnh đại diện
Huỷ bỏ
Bài viết liên quan Trả lời Lượt xem Hoạt động
3
thg 10 23
8801
1
thg 9 23
3323
1
thg 5 23
2265
2
thg 4 23
2824
1
thg 3 23
2209