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. ManyToManyField
s.
Source:stackexchange.com