def save_review_from_row(review_row): review = Review() review.user_id = User.objects.get(id=review_row[0]) review.user_name = User.objects.get(id=review_row[0]) review.movie = Movie.objects.get(id=review_row[1]) review.rating = review_row[2] review.pub_date = datetime.datetime.now(tz=timezone.utc) review.save()
def add_review(businessId): requestData = request.get_json() try: feedback = check_review(requestData.get('feedback')) except Exception as exception: return response_message(exception.args, status_code=500) auth_token = request.headers.get("Authorization") user = get_user(auth_token) if not isinstance(user, User): return response_message("Please login to review business", 401) business = Business.query.filter_by(id=businessId).first() if not business: return response_message("The business you requested does not exist", status_code=404) review = Review(feedback) review.user_id = user.id review.business_id = business.id review.save() return response_message("Your review has been added", 201)