1👍
✅
Use related_name
, just as you would with a normal ForeignKey
or ManyToManyField
:
class RecipeIngredients(models.Model):
recipe = models.ForeignKey(Recipe, related_name='ingredient_quantities')
And then:
>>> r = Recipe.objects.get(id=1)
>>> ingredients = r.ingredient_quantities.all()
👤knbk
Source:stackexchange.com