I am trying to create a Django model for a recipe database. I'm having trouble writing a model that will account for a variable amount of ingredients(not every recipe has the same amount of ingredients). Here is what I have so far:
class Recipe(models.Model):
'''A recipe class to input new recipes'''
recipe = models.CharField(max_length=50)
ingredient = models.ForeignKey(Ingredient, null=True, on_delete=models.SET_NULL)
quantity = models.CharField(max_length=1)
cuisine = models.ForeignKey(Cuisine, null=True, on_delete=models.SET_NULL)
def __str__(self):
return self.recipe
I'm stuck trying to figure out how to associate one recipe with multiple ingredients in the database. Right now, I've only managed to create one ingredient per recipe. The foreign keys are for other created classes that describe individual ingredients and cuisines.