示例#1
0
def create_donut():
    """Add a donut, and return data about the new donut.

    Return JSON like:
        {donut: [{id, flavor, rating, size, image}]}
    """

    data = request.json

    donut = Donut(
        flavor=data['flavor'],
        rating=data['rating'],
        size=data['size'],
        image=data['image'] or None,
    )

    db.session.add(donut)
    db.session.commit()

    return (jsonify(donut=donut.to_dict()), 201)