1👍
✅
“Storage” that holds 2 “StorageType”
That means Storage
can have many StorageType
and StorageType
can have Storages. Make a new ManyToMany Field in the storage.
class Storage(models.Model):
storage_types = models.ManyToManyField(StorageType)
def __unicode__(self):
return str(self.id)
class StorageType(models.Model):
tripa = 'Tripa'
portada = 'Portada'
type_choice = (
(tripa, 'Tripa'),
(portada, 'Portada'),
)
sto_type = models.CharField(max_length=9, choices=type_choice, default=tripa)
paper_type = models.ForeignKey(Paper)
paper_qnty = models.IntegerField(blank=True, default=0)
web_paper_qnty = models.IntegerField(blank=True, default=0)
def __unicode__(self):
return '%s of %s' %(self.sto_type, str(self.storage))
Then read Django Many-to-many relationships
Source:stackexchange.com