I have a Django model representing a simple grocery list, as follows (truncated for brevity)
class Meal(models.Model):
name = models.CharField(max_length = 200)
ingredients = models.ManyToManyField(Ingredient)
class GroceryList(models.Model):
name = models.CharField(max_length = 200)
meals = models.ManyToManyField(Meal)
ingredients = models.ManyToManyField(Ingredient)
This allows a GroceryList to contain both Meal objects, and Ingredient objects. (This way a list can group ingredients together when they’re needed for a Meal.)
The problem is, I want a GroceryList to be able to contain the same Meal twice, or more. What’s the most efficient solution?
I had considered wrapping the Meal class in an object (‘MealContainer‘) that maintained both the underlying Meal, alongside a quantity, but that seems a little heavy-handed.
Perhaps consider a
throughmodel with aquantityfield.