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 trialDani Nanestean
2,659 PointsI'm stuck on this exercise, and the writing "Bummer: Try again!" doesn't help me understand the mistake
What I did:
models.py (first file)
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
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):
name = CharField()
description = CharField()
quantity = DecimalField()
measurement_type = CharField()
recipe = ForeignKeyField(Recipe, backref='ingredients')
class Meta:
database = DATABASE
class Ingredient(Model):
name = CharField()
description = CharField()
quantity = DecimalField()
measurement_type = CharField()
recipe = ForeignKeyField(Recipe, backref='ingredients')
class Meta:
database = DATABASE
resources/ingredients.py (second file)
from flask_restful import Resource
import models
Where is the mistake?
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
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):
name = CharField()
description = CharField()
quantity = DecimalField()
measurement_type = CharField()
recipe = ForeignKeyField(Recipe, backref='ingredients')
class Meta:
database = DATABASE
class Ingredient(Model):
name = CharField()
description = CharField()
quantity = DecimalField()
measurement_type = CharField()
recipe = ForeignKeyField(Recipe, backref='ingredients')
class Meta:
database = DATABASE
from flask_restful import Resource
import models
3 Answers
Steven Parker
231,533 PointsIn the code shown above, the class definition appears twice. Eliminate the duplicate.
But also, the video lesson example does not use the backref kwarg in the ForeignKeyField. Try leaving that out.
Dani Nanestean
2,659 PointsI made all the changes reported Always "Bummer: Try again!" keeps giving me
Rohald van Merode
Treehouse StaffHey Dani Nanestean 👋
I've just tried submitting your code after making the changes Steven suggested and your code seems to be passing fine on the first task after doing so. You'll want to make sure all the duplicate code in your snippets has been removed and remove the back reference (backref='ingredients'
) from the foreign key definition as Steven pointed out.
For your reference here is what should be left of your code after making the suggested adjustments:
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):
name = CharField()
description = CharField()
quantity = DecimalField()
measurement_type = CharField()
recipe = ForeignKeyField(Recipe)
class Meta:
database = DATABASE
Hope this clears things up!
Dani Nanestean
2,659 Pointsit's ok now, thank you very much! :)
Dani Nanestean
2,659 PointsDani Nanestean
2,659 Points"I need your help to build an API for creating recipes. I have the recipe model done but we need one to represent each of the ingredients in a recipe.
Make a new Model named Ingredient. I've added comments to the models.py to describe the fields. Feel free to check the models and fields documenation if you need to. Don't forget to set the database attribute in the Meta class.
Thanks!"
This is what I have to do