0

では、モデルの設定方法についてアドバイスをお願いします。開発中のレシピモデルがあります(タブレットをキッチンに置く予定です)。私ができるようにしたいのは、各レシピに材料リストを持たせることですが、材料リストに一致する対応する数量リストも用意することです。アイデアは、手元にある材料とその量を追跡するために使用される材料モデルがあり、レシピモデルには独自の材料リストと必要な量が含まれるということです。そうすれば、私が作る材料があるレシピをアプリに表示させ、材料がないレシピを非表示にすることができます(または実際にはもっと複雑になりますが、それがアイデアです)。これが私の現在の設定です:

成分model.py

class Unit_of_Measure(models.Model):

   """Unit_of_Measure model. This is used as the foriegnkey for the Quantity model unit_of_measure key."""

   class Meta:
           verbose_name_plural = "Units of Measure"

   def __unicode__(self):
           return self.unit_of_measure

   unit_of_measure = models.CharField(max_length=200)

class Location(models.Model):

   """Location model. This is used a the foriegnkey for the Ingredient model location key."""

   class Meta:
           verbose_name_plural = "Locations"

   def __unicode__(self):
           return self.place

   place = models.CharField(max_length=200)

class Ingredient(models.Model):

   """Ingredients model. Includes ingredient title, quantity on hand, location of ingredient (foreignkey), expiration date, and if it is a shop for ingrdient."""

   class Meta:
           verbose_name_plural = "Ingredients"

   def __unicode__(self):
           return self.title

   title = models.CharField(max_length=200)
   quantity = models.CharField(max_length=200)
   unit_of_measure = models.ForeignKey(Unit_of_Measure)
   location = models.ForeignKey(Location)
   expiration_date = models.DateTimeField()
   shop_for = models.BooleanField()

レシピmodel.py

class RecipeType(models.Model):

   """Recipe type model. This is used as the foreign key for the Recipe model recipe style."""

   def __unicode__(self):
           return self.style

   style = models.CharField(max_length=200)

class Recipe(models.Model):

   """Recipe model. Includes recipe title, recipe style (dinner, snack, etc..), ingredient list (foreignkey), recipe instructions, storage style, and expiration date."""

   class Meta:
           verbose_name_plural = "Recipes"

   def __unicode__(self):
           return self.title

   title = models.CharField(max_length=200)
   style = models.ForeignKey(RecipeType)
   required_ingredient_list = models.ManyToManyField(Ingredient, related_name='additional_ingredient_list')
   additional_ingredient_list = models.ManyToManyField(Ingredient, related_name='required_ingredient_list', blank=True)
   recipe_instruction = models.TextField()
   storage_style = models.CharField(max_length=200)
   expiration_date = models.DateTimeField()

では、2つのフィールドリストを一致させる方法について何か提案はありますか?「required_ingredient_list」が「required_ingredient_quantity_list」と一致するようなものですか?またはより良い解決策?または一般的な提案はありますか?現在、材料でレシピを並べ替えることができますが、材料モデルの量はキッチンにある手元の量であるため、レシピが使用する量を表すフィールドは実際にはありません。recipe_instructionフィールドに表示されます。ハルプ!

4

1 に答える 1

0

「スルーモデル」を使用して、レシピを材料にリンクします。中間モデルには、関連付けられた単位と、それに関連付けられた数値または文字列のメジャーを含めることができます。

于 2012-05-04T03:23:22.463 に答える