示例#1
0
文件: api.py 项目: deejay1/ralph
 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 []
示例#2
0
文件: api.py 项目: pombreda/ralph
 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 []