How to select multiple values in one field?
class ProductAttribute(models.Model):
_inherit = "product.attribute"
exclude = fields.Many2many('product.attribute', string='Exclude')
In this field I want to select several attributes. Or need to use One2many ??
You have to specify the relation name manually because the source and destination models are the same:
relation='product_attribute_exclude'
In this case, column1
and column2
are not provided and will be generated automatically and should be equal to product_attribute_id
which will raise a psycopg2.errors.DuplicateColumn
error, so you need to provide their names explicitly.
Try the following example:
exclude = fields.Many2many('product.attribute', relation='product_attribute_exclude',
column1="attribute_id", column2="exclude_id", string='Exclude')
It is enough to provide only one column name different from product_attribute_id
to fix the DuplicateColumn
error