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 trialKennedy Malonga
18,790 PointsMake 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
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
from flask.ext.restful import Resource
import models
1 Answer
jb30
44,806 Pointsclass 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
.