def obj_update(self, bundle, **kwargs): #Edit case many to many handling. First clear out the previous related objects and create new objects bundle = super(AdoptionVerificationResource, self).obj_update(bundle, **kwargs) user_id = None if bundle.request.user: user_id = bundle.request.user.id adoptionverification_id = bundle.data.get('id') del_objs = AdoptionNonNegotiableVerfication.objects.filter(adoptionverification__id=adoptionverification_id).delete() nonnego_list = bundle.data.get('nonnegotiable') for pma in nonnego_list: pma = AdoptionNonNegotiableVerfication(adoptionverification_id=adoptionverification_id, nonnegotiable_id=pma['nonnegotiable_id'], adopted=pma['adopted'], user_created_id = user_id) pma.save() return bundle
def obj_create(self, bundle, **kwargs): nonnego_list = bundle.data.get('nonnegotiable') if nonnego_list: bundle = super(AdoptionVerificationResource, self).obj_create(bundle, **kwargs) user_id = None if bundle.request.user: user_id = bundle.request.user.id adoptionverification_id = getattr(bundle.obj,'id') for pma in nonnego_list: try: attendance = AdoptionNonNegotiableVerfication(adoptionverification_id=adoptionverification_id, nonnegotiable_id=pma['nonnegotiable_id'], adopted=pma['adopted'], user_created_id = user_id) attendance.save() except Exception, e: raise AdoptionVerificationNotSaved('For AdoptionVerification with id: ' + str(adoptionverification_id) + ' pma is not getting saved. pma details: '+ str(e)) return bundle