Files
project_banjo_app/project/app/models.py
2026-04-03 18:12:50 -04:00

34 lines
1.0 KiB
Python

from banjo.models import Model, StringField, IntegerField, ForeignKey
from datetime import datetime
class Recipe(Model):
name = StringField()
url = StringField()
def to_dict(self):
return {
"id": self.id,
"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}