def movie_add_relation(): """ Add actor to movie's cast """ data = get_request_data() if 'id' in data.keys(): try: row_id = int(data['id']) relation_id = int(data['relation_id']) except: err = 'Id must be integer' return make_response(jsonify(error=err), 400) obj = Actor.query.filter_by(id=relation_id).first() try: movie = Movie.add_relation(row_id, obj) rel_movie = { k: v for k, v in movie.__dict__.items() if k in MOVIE_FIELDS } rel_movie['cast'] = str(movie.cast) except: err = 'Record with such id does not exist' return make_response(jsonify(error=err), 400) return make_response(jsonify(rel_movie), 200) else: err = 'No id specified' return make_response(jsonify(error=err), 400)
def movie_add_relation(): """ Add actor to movie's cast """ data = get_request_data() if 'id' in data.keys(): try: row_id = int(data['id']) relation_id = data['relation_id'] obj_actor = Actor.query.filter_by(id=relation_id).first() movie = Movie.add_relation(row_id, obj_actor) rel_movie = { k: v for k, v in movie.__dict__.items() if k in MOVIE_FIELDS } rel_movie['cast'] = str(movie.cast) return make_response(jsonify(rel_movie), 200) except: err = 'Id must be integer' return make_response(jsonify(error=err), 400)