예제 #1
0
def post_categories():
    data, _ = create_category_serializer.loads(request.data)
    category = Categories(**data['attributes'])
    db.session.add(category)
    db.session.commit()
    response = jsonify(data=read_category_serializer.dump(category).data)
    response.status_code = 201
    return response
예제 #2
0
def get_category_by_id(id):
    category = Categories.query.get(id)
    data, errors = read_category_serializer.dump(category)
    data['relationships'] = category.get_relationships()
    return jsonify(data=data)
예제 #3
0
def get_categories():
    categories = Categories.query.all()
    data, errors = read_category_serializer.dump(categories, many=True)
    return jsonify(data=data)