def Category_insert(): print("테스트 카테고리 입력 시작...") category_list = ["게임", "스포츠", "연예인", "방송"] for i in range(0, 20): category = Category() if i <= 3: category.category_name = category_list[i] else: category.category_name = f"카테고리{i}" category.board_num = 0 db.session.add(category) db.session.commit() print("테스트 카테고리 입력 성공")
def save_categories(business_id, cat_jarray): for name in cat_jarray: category = Category() category.business_id = business_id category.category_name = name try: category.save() except InternalError: print "i dont care" pass
def add_category(): data = request.get_json() category_name = data.get('category_name') if Category.query.filter(Category.category_name == category_name).first(): return jsonify({'error':'이미 있는 카테고리입니다.'}), 409 if not category_name : return jsonify({'error':'이름을입력해주세요'}), 403 category = Category() category.category_name = category_name db.session.add(category) db.session.commit() categories = Category.query.all() return jsonify([cat.serialize for cat in categories]), 201
def save_categories(business_id, cat_jarray): for name in cat_jarray: category = Category() category.business_id = business_id category.category_name = name category.save()