def patch(self, id=None): address = self.get_resource_with_ids(Address, id) json_data = request.get_json() try: data = address_patch_schema.load(json_data, partial=True) except ValidationError as err: raise RequestException("Invalid input data", 400, err.messages) try: address.update(**data) except Exception as err: raise RequestException( payload={APIConst.INPUT: json_data}) from err result = address_schema.dump(Address.get_with_id(address.id)) response = jsonify({ APIConst.MESSAGE: 'updated address {}'.format(id), APIConst.DATA: result }) return response
def load(self, data, many=None, partial=None): de_data = super().load(data, many=many, partial=partial) de_data = [de_data] if not many else de_data for de_data_item in de_data: location_dicts = de_data_item.get('locations') if location_dicts is None: continue locations = [] for loc_dict in location_dicts: id = loc_dict.get('id') print(id) loc = None if id: loc = Address.get_with_id(id) else: loc = Address.create(commit=False, **loc_dict) locations.append(loc) de_data_item['locations'] = locations return de_data if many else de_data[0]