Unique Field Values ​​and Relationships ManyToMany

Let's say I have a class structure that is defined below:

Class Item(models.Model): ... price = models.IntegerField() upc = models.IntegerField() ... Class Store(models.Model): ... inventory = models.ManyToManyField(Item) ... 

Basically, I want storage models to have access to the same inventory. However, the price value in the item model will be unique for each store that is associated with it. for example, I may have an instance of an element model called a bike, which all stores will have access to. For all stores, the upc (barcode) will be the same, but the price will be different for each store. Is there a way to implement this relationship using this class structure?

+6
django django-models
source share
1 answer

Use an explicit through table. See the documentation .

+7
source share

All Articles