Welcome to the Treehouse Community

Want to collaborate on code errors? Have bugs you need feedback on? Looking for an extra set of eyes on your latest project? Get support with fellow developers, designers, and programmers of all backgrounds and skill levels here with the Treehouse Community! While you're at it, check out some resources Treehouse students have shared here.

Looking to learn something new?

Treehouse offers a seven day free trial for new students. Get access to thousands of hours of content and join thousands of Treehouse students and alumni in the community today.

Start your free trial

Python Flask REST API Resourceful Blueprints Ingredient Resource

Thanks for making the model! Now, though, I need a resource created for it. Just create two Resource classes, Ingredient

Thanks for making the model! Now, though, I need a resource created for it. Just create two Resource classes, IngredientList and Ingredient. Give them both a get method that just returns a string. You can put anything you want in the string. Remember, the get method for the Ingredient resource will need to take an id argument, too.

models.py
import datetime

from peewee import *

DATABASE = SqliteDatabase('recipes.db')


class Recipe(Model):
    name = CharField()
    created_at = DateTimeField(default=datetime.datetime.now)

    class Meta:
        database = DATABASE


# TODO: Ingredient model
# name - string (e.g. "carrots")
# description - string (e.g. "chopped")
# quantity - decimal (e.g. ".25")
# measurement_type - string (e.g. "cups")
# recipe - foreign key
class Ingredient(Model):
    name = CharField()
    description = CharField()
    quantity = DecimalField()
    measurement_type = CharField()
    recipe = ForeignKeyField(Recipe)

    class Meta:
        database = DATABA
resources/ingredients.py
from flask.ext.restful import Resource

import models


class IngredientList(Resource):
    def get(self):
        return 'IngredientList'


class Ingredient(Resource):
    def get(self, id):
        return 'Ingredient'

1 Answer

Check your DATABASE in your Meta for Ingredients. You have a small typo