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 trialTeam GDiz
Courses Plus Student 24,942 PointsProblem with challenge. What am i doing wrong?
Trying this one out.
https://teamtreehouse.com/library/flask-rest-api/resourceful-blueprints/ingredient-resource
Can anyone tel me what I'm doing wrong with my model?
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 = ForeignFieldKey(Recipe, related_name = 'review_set')
class Meta:
database = DATABASE
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 = ForeignFieldKey(Recipe, related_name = 'review_set')
class Meta:
database = DATABASE
from flask.ext.restful import Resource
import models
1 Answer
Nick Osborne
4,612 PointsHi Gaurav, The code is good but it's "ForeignKeyField" not "ForeignFieldKey".
Team GDiz
Courses Plus Student 24,942 PointsTeam GDiz
Courses Plus Student 24,942 PointsThat solved it. Thanks :)