[Django]-Django models to hold a list of objects from another Model

4👍

A ManyToManyField is the way to go, you can work with:

class Cart(models.Model):
    items = models.ManyToManyField(
        'Product',
        related_name='carts'
    )

class Product(models.Model):
    # …

The Django documentation has a section on many-to-many relations that specifies how to add, remove, query, etc. ManyToManyFields.

Leave a comment