generated from mwc/project_banjo_app
Imported recipes and ensured the they work by searching recipe name and ingredients.
I’m proud that importing recipes works and the ingredients, steps, and notes show up correctly. I also learned how to set up models and link them with views in Banjo, which was really helpful. This project taught me a lot about building a small app with models, views, and working APIs.
This commit is contained in:
32
project/app/models.py
Normal file
32
project/app/models.py
Normal file
@@ -0,0 +1,32 @@
|
||||
from banjo.models import Model, StringField, IntegerField, ForeignKey
|
||||
from datetime import datetime
|
||||
|
||||
class Recipe(Model):
|
||||
name = StringField()
|
||||
url = StringField()
|
||||
|
||||
def to_dict(self):
|
||||
return {
|
||||
"name": self.name,
|
||||
"url": self.url,
|
||||
"ingredients": [i.text for i in self.ingredients.all()],
|
||||
"steps": [s.text for s in self.steps.order_by("order")],
|
||||
"notes": [n.to_dict() for n in self.notes.order_by("creation")],
|
||||
}
|
||||
|
||||
class Ingredient(Model):
|
||||
text = StringField()
|
||||
recipe = ForeignKey("Recipe", related_name="ingredients")
|
||||
|
||||
class Step(Model):
|
||||
text = StringField()
|
||||
order = IntegerField()
|
||||
recipe = ForeignKey("Recipe", related_name="steps")
|
||||
|
||||
class Note(Model):
|
||||
text = StringField()
|
||||
creation = StringField(default=lambda: datetime.now().strftime("%Y-%m-%d %H:%M:%S"))
|
||||
recipe = ForeignKey("Recipe", related_name="notes")
|
||||
|
||||
def to_dict(self):
|
||||
return {"date": self.creation, "note": self.text}
|
||||
Reference in New Issue
Block a user