project_banjo_app/cookbook/app/models.py

42 lines
1.1 KiB
Python

from banjo.models import (
Model,
StringField,
IntegerField,
FloatField,
ForeignKey,
)
from django.db.models import DateTimeField
class Recipe(Model):
name = StringField()
url = StringField()
def to_dict(self):
return {
"name": self.name,
"ingredients": [ing.text for ing in self.ingredients.all()],
"instructions": [step.text for step 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):
recipe = ForeignKey("Recipe", related_name="steps")
text = StringField()
order = IntegerField()
class Note(Model):
recipe = ForeignKey("Recipe", related_name="notes")
creation=DateTimeField(auto_now_add=True)
text=StringField()
def to_dict(self):
return {
"date": self.creation.strftime("%A %B %-d, %Y %I:%M %p"),
"note": self.text,
}