Overslaan naar inhoud
Menu
Je moet geregistreerd zijn om te kunnen communiceren met de community.
Deze vraag is gerapporteerd
1 Beantwoorden
7692 Weergaven

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
Annuleer
Beste antwoord

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
Annuleer
Gerelateerde posts Antwoorden Weergaven Activiteit
3
okt. 23
8487
1
sep. 23
3197
1
mei 23
2144
2
apr. 23
2659
1
mrt. 23
2071