def hydrate_m2m(self, bundle): ci = bundle.obj CIAttributeValue.objects.filter(ci=ci).delete() for attr_data in bundle.data.get('attributes', []): attribute = CIAttribute.objects.get(name=attr_data['name']) attribute_value = CIAttributeValue( ci=ci, attribute=attribute, ) attribute_value.save() attribute_value.value = attr_data['value'] return []
def create_attributes(self): self.attribute1 = CIAttribute( name='Attribute 1', attribute_type=CI_ATTRIBUTE_TYPES.INTEGER, choices='', ) self.attribute1.save() self.attribute1.ci_types.add(self.types[0]), self.attribute_value1 = CIAttributeValue( ci=self.ci1, attribute=self.attribute1, ) self.attribute_value1.value = 10 self.attribute_value1.save()