콘텐츠로 건너뛰기
메뉴
커뮤니티에 참여하려면 회원 가입을 하시기 바랍니다.
신고된 질문입니다
1 회신
7583 화면

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
8075
1
9월 23
2994
1
5월 23
1944
2
4월 23
2506
1
3월 23
1899