Specifying Units in Django -
i'm creating small app counts calories in recipes. i'm curious know if there better way this. each recipe has ingredients. each ingredient has amount, weight, , calorie profile.
so instance:
- recipe: flourless nutella cake
- ingredient: eggs
- amount: 4
- weight: large eggs (could cups or oz or whatever)
- calories: 312 (calculated amount * weight)
- ingredient: nutella
- amount: 8.5
- weight: ounces
- calories: 850
- ingredient: eggs
here models.py:
from foodlist.models import food, weight
class ingredient(models.model):
food = models.foreignkey(food)
weight = models.foreignkey(weight)
amount = models.floatfield(default=1.0)...
class recipe(models.model):
ingredients = models.manytomanyfield(ingredient, blank=true, null=true)
...
the problem every time want make new recipe different amount of eggs, first have make new ingredient containing correct amount of eggs. have 1 ingredient says "4 large eggs" , ingredient says "2 large eggs."
i'm using inlines in admin see together, still seems rather cumbersome , there better way.
is there way can under recipe instead of intermediate step in ingredient?
remove amount field ingredients model, , create new model this:
class amount(models.model): units = model.integerfield(default=1) ingredient = models.foreignkey(ingredient) recipe = models.foreignkey(recipe)
as long keep amounts separate ingredients model, can put ingredients in , track amounts using "units" field each recipe.
Comments
Post a Comment