> I'm working on an app for planning balanced daily diets.  And I'm
> having trouble figuring out how to set up my models.  I have:
>
> Ingredient(models.Model):
>     ingredient_name = CharField(max_length=50)
>     unit = CharField(max_length=15)
>     calories = DecimalField(max_digits=6, decimal_places=2)
>
> Recipe(models.Model):
>     recipe_name = CharField(max_length=50)
>     ingredients = ManyToMany(Ingredient)
>     amount = DecimalField(max_digits=6, decimal_places=2)
>
> An ingredient can be in many recipes and a recipe has many
> ingredients.  The thing is, in a Recipe I want to have an arbitrary
> number of ingredients, and I need for each ingredient to be associated
> with an amount. I could use multiple ForeignKey fields from in Recipe
> to Ingredient, and multiple amount fields in Recipe, but that seems
> klunky. Is there a "right" way to do this?

You can use the "through" attribute on your M2M definition. See:
http://docs.djangoproject.com/en/dev//topics/db/models/#extra-fields-on-many-to-many-relationships

That will allow you to add fields like amount to each M2M relation.

-RD
--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the Google Groups 
"Django users" group.
To post to this group, send email to django-users@googlegroups.com
To unsubscribe from this group, send email to [EMAIL PROTECTED]
For more options, visit this group at 
http://groups.google.com/group/django-users?hl=en
-~----------~----~----~----~------~----~------~--~---

Reply via email to