[Answer]-How to create a database table based off a list

1👍

Sounds like you would need to use Django’s many to many relationship. In your example, the Recipe would contain a many to many relationship to the Food.

from django.db import models

class Food(models.Model):
    name = models.CharField(max_length=30)

    def __str__(self):
        return self.name

class Recipe(models.Model):
    title = models.CharField(max_length=100)
    description = models.TextField()
    ingredients = models.ManyToManyField(Food)

    def __str__(self):
        return self.title

Django 1.7 Docs: many_to_many

Leave a comment