def get_all_with_products(): models = Category.get_all_with_products(throw=True) # res = [] # for model in models: # cate_res = {'label': model.name, 'value': model.id} # res.append(cate_res) # if getattr(model, 'products'): # cate_res.setdefault('children', []) # for product in model.products: # cate_res['children'].append({'label': product.name, 'value': product.id}) return models