Skip to Content
मेन्यू
This question has been flagged
1 Reply
7933 Views

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

Avatar
Discard
Best Answer

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

Avatar
Discard
Related Posts Replies Views Activity
3
सित॰ 25
367
3
अक्तू॰ 23
9181
1
सित॰ 23
3456
1
मई 23
2437
2
अप्रैल 23
3018