def get_business_info(): """return a json element with businesses associated to the given category""" category = request.args.get("searchTerm", "") try: # get category object with search term category_object = Category.get_category_by_name(category) except NoResultFound: return jsonify({"data": "Can't find matches"}) # getting businesses associated with elected category try: businesses = category_object.categories_business # when we have multiple matches, we get a list -> categories_business throws # AttributeError (list does not have that attribute except AttributeError: # todo: turn list of objects into one big object to pass to JS return jsonify({"data": "Can't find matches"}) return jsonify(Business.serialize_business_object(businesses))