1👍
You can access the Ingredient object fields through the ingredient foreign key:
class Recipe(models.Model):
...
def cost_per_ingredient(self):
cost_per_ingredient = self.ingredient_quantity * self.ingredient_name.cost_per_unit
return cost_per_ingredient
I would suggest to call it "ingredient" though, not "ingredient_name".
Source:stackexchange.com