I'm working on Django website that should give a possibility to select cooking recipes containing the ingredients provided by user. So in brief, the idea of the site is "things you could make from the food in your refrigerator".
So I made 2 models
class Recipe (models.Model):
name = models.CharField(max_length=255)
ingredients = models.ManyToManyField(Ingredient)
class Ingredient (models.Model):
name = models.CharField(max_length=255)
Let's imagine, that I have as list ['egg','bread','meat','onion']
.
Now I need select all Recipes that could be made from that list on ingredients.
The problem is, that some recipes may have only some of ingredients from the list.
For example:
So my question is: could it be possible to select all recipes that could be made from the list of the ingredients AND select the closest recipes that could be made from the list of ingredients + some ingredients from the shop?
For example: recipes has 3 elements from 4, so we add it to the result.
Have you tried:
Receipt.objects.filter(ingredients__name__in=['egg','bread','meat','onion'])
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With