Zum Inhalt springen
Menü
Sie müssen registriert sein, um mit der Community zu interagieren.
Diese Frage wurde gekennzeichnet
2 Antworten
4204 Ansichten

i'm creating a moudle in odoo 11 and i wanna use many2one as selection field , the problem is on the of the city'ville en francais' the dropdown works and it saves the id of the city(from database) but the name is like obj.ville,1(it shows the name of the module, id instead of the name of the city in database)

Code:

from odoo import models, fields, api


Class villeMO(models.Model):

_name = 'ville.mo'

  ville = fields.Char(string="ville",required=True)

       Class paya(models. Model):

_name='paya.mo'

city = fields.Many2one('ville.mo',ondelete="cascade",string="city")


Avatar
Verwerfen
Beste Antwort

Odoo uses by default the “name” field to display the record as a string (display name), so you could rename the field “ville” to “name”. 

You can also set the attribute “_rec_name” = “ville” to tell Odoo to use the “ville” field for the records display name.

So like this:

Class villeMO(models.Model):

    _name = 'ville.mo'

    _rec_name = 'ville'

    ville = fields.Char(string="ville",required=True)

Avatar
Verwerfen
Autor Beste Antwort

thank you very much for your help

Avatar
Verwerfen

No problem! An upvote would be appreciated :)

Verknüpfte Beiträge Antworten Ansichten Aktivität
2
Aug. 25
2455
3
Feb. 25
3785
0
Mai 24
46
1
Apr. 24
3503
4
Sept. 23
5036