Answer the question
In order to leave comments, you need to log in
In Django 1.11, how do I create additional fields for a many-to-many relationship?
from django.db import models
from food.models import Food
class Recipe(models.Model):
description = models.TextField(null=True, blank=True)
ingridients = models.ManyToManyField(
Food,
through=Ingredients,
through_fields=('recipe', 'food')
)
class Ingredients(models.Model):
recipe = models.ForeignKey(Recipe, on_delete=models.CASCADE)
food = models.ForeignKey(Food, on_delete=models.CASCADE)
quantity = models.DecimalField(null=True, blank=True, max_digits=6, decimal_places=2)
Answer the question
In order to leave comments, you need to log in
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question