def add_favorite(): # add a favorited name to the Favorite table in the DB new_fav = Favorite() new_fav.user_username = session['user'] new_fav.name_id = request.json["name_id"] new_fav.favorited_name = request.json["favorited_name"] new_fav.name_gender = request.json["name_gender"] db.session.add(new_fav) db.session.commit() return jsonify(success=True)
def add_favorite(): # first make sure name doesn't exist in DB name = request.json["favorited_name"] try: find_name = Favorite.query.filter_by( favorited_name=name).first().favorited_name return jsonify(duplicate_name=True) except AttributeError: # add a favorited name to the Favorite table in the DB new_fav = Favorite() new_fav.user_username = session['user'] new_fav.name_id = request.json["name_id"] new_fav.favorited_name = request.json["favorited_name"] new_fav.name_gender = request.json["name_gender"] db.session.add(new_fav) db.session.commit() return jsonify(success=True)