How to define the values listed in a selection widget for a Many2One field?

I have a class with a Many2One field to product.uom as per below and the form uses . I tried to figure it out by looking at the country field on party.address in vain.

class UnitCode(ModelSQL, ModelView):
    "Unit Code"
    __name__ = 'masterol_foods.unitcode'

    unit = fields.Many2One('product.uom','Unit', required=True)
    code = fields.Char('Code', required=True)

You can define domain to filter the results. Example 1, Example 2
I don’t know if it’s what are you looking for, if not, please try to define better your needs.

1 Like

No, I don’t want to filter the result. I want to define what select drop down options are show to the user in the UI. At the moment what is shown is the ID of the records from the database.

What is shown is the rec_name of the model. If no rec_name is defined, the id is shown.

Thanks for that Oscar.

A good example of how to do this is here.

Also, in my example the unit field is a Many2One so the the rec_name attribute of the related field is needed as per below:

    def get_rec_name(self, name):
        return '%s (%s)' % (self.unit.rec_name, self.code)
1 Like

This topic was automatically closed 30 days after the last reply. New replies are no longer allowed.