Retrieve DictSchemaMixin from Dict entry

Hi,
I have added a custom dict field to the product module similar to the attributes:

class Property(DictSchemaMixin, ModelSQL, ModelView):
    'Property'
    __name__ = 'property.property'
...
properties = fields.Dict('property.property', 'Properties' )

Now I can create multiple properties and assign them to a product e.g.

my_product.properties = {'property_name_1: 'asdf', ...}

My question is, if there is a way to get back the DictSchemaMixin record from an entry in this dictionary. Because the names are not unique, it does not seem that there is a 1:1 relationship or am I missing something?
Thanks

Hi,

Not sure IIUC, but yes, you can get the information of the DictSchemaMixin directly in the Property class instance. Look-up the docs for the available variables.

Thanks for your reply, but my problem is getting the Property class in the first place. Let me clarify a bit:
I created two properties with the same name:
1.


2.

Now in the product form I can choose one of them and assign a value of the selection. But when I then check the properties field e.g. with proteus I get only a dictionary like this {'my_property': '1'} from which I can not retrieve the Property Instance.
If this relies on the name being unique, why is it not enforced?

Indeed they should be unique (and it is something missing to product_attribute: Product attribute name must be unique (#13574) · Issues · Tryton / Tryton · GitLab).

It is not enforced by the Mixin because it does not know based on which columns.

But it will be good to document Document that names of DictSchemaMixin must be unique (#13575) · Issues · Tryton / Tryton · GitLab

Makes sense, thank you.

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