Welcome to the Treehouse Community

The Treehouse Community is a meeting place for developers, designers, and programmers of all backgrounds and skill levels to get support. Collaborate here on code errors or bugs that you need feedback on, or asking for an extra set of eyes on your latest project. Join thousands of Treehouse students and alumni in the community today. (Note: Only Treehouse students can comment or ask questions, but non-students are welcome to browse our conversations.)

Looking to learn something new?

Treehouse offers a seven day free trial for new students. Get access to thousands of hours of content and a supportive community. Start your free trial today.

Python Flask REST API Resourceful Blueprints Ingredient Resource

Make a new Model named Ingredient. I've added comments to the models.py to describe the fields. Feel free to check the m

Im struggling heavy

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


class Ingredient(Model):
     recipe = ForeignKeyField(Recipe, related_name='review_set')

    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
resources/ingredients.py
from flask.ext.restful import Resource

import models

1 Answer

class Ingredient(Model):
     recipe = ForeignKeyField(Recipe, related_name='review_set')

    class Meta:
        database = DATABASE

In addition to the field recipe, you also need to add the fields name, description, quantity, and measurement_type. For string fields, you can use CharField(), and for decimal fields, you can use DecimalField().

You also have inconsistent indentation. The line recipe = ForeignKeyField(Recipe, related_name='review_set') has 5 spaces before it, and the line class Meta: has 4 spaces before it. They should be indented the same number of spaces.

Foreign key fields do not need to include a related_name. It does not matter for this challenge if you include the related_name, but you might want a more descriptive name to refer to an Ingredient from a Recipe than review_set.