2
0
mirror of https://github.com/inventree/InvenTree.git synced 2025-06-13 10:35:40 +00:00

Expose part parameters to Part label templates

This commit is contained in:
Oliver
2021-07-21 22:05:52 +10:00
parent 20a30f317f
commit afde997cf9
3 changed files with 19 additions and 0 deletions

View File

@ -1904,6 +1904,23 @@ class Part(MPTTModel):
return self.parameters.order_by('template__name')
def parameters_map(self):
"""
Return a map (dict) of parameter values assocaited with this Part instance,
of the form:
{
"name_1": "value_1",
"name_2": "value_2",
}
"""
params = {}
for parameter in self.parameters.all():
params[parameter.template.name] = parameter.data
return params
@property
def has_variants(self):
""" Check if this Part object has variants underneath it. """