def hydrate_m2m(self, bundle): ci = bundle.obj CIRelation.objects.filter( Q(child_id=ci.id) | Q(parent_id=ci.id) ).delete() for relation_data in bundle.data.get('related', []): relation = CIRelation() try: type_id = CI_RELATION_TYPES.id_from_name(relation_data['type']) except ValueError: raise tastypie.exceptions.BadRequest( 'No such relation type {}'.format(relation_data['type']) ) relation.type = type_id other_ci = CI.objects.get(id=relation_data['id']) if relation_data['dir'] == 'OUTGOING': relation.parent = ci relation.child = other_ci elif relation_data['dir'] == 'INCOMING': relation.parent = other_ci relation.child = ci else: raise tastypie.exceptions.BadRequest( 'dir should be OUTGOING or INCOMING' ) relation.save() return []
def hydrate_m2m(self, bundle): ci = bundle.obj CIRelation.objects.filter(Q(child_id=ci.id) | Q(parent_id=ci.id)).delete() for relation_data in bundle.data.get('related', []): relation = CIRelation() try: type_id = CI_RELATION_TYPES.id_from_name(relation_data['type']) except ValueError: raise tastypie.exceptions.BadRequest( 'No such relation type {}'.format(relation_data['type'])) relation.type = type_id other_ci = CI.objects.get(id=relation_data['id']) if relation_data['dir'] == 'OUTGOING': relation.parent = ci relation.child = other_ci elif relation_data['dir'] == 'INCOMING': relation.parent = other_ci relation.child = ci else: raise tastypie.exceptions.BadRequest( 'dir should be OUTGOING or INCOMING') relation.save() return []