概念:django造型
飲料是由部件組成。例如。 10毫升伏特加。在某些收據中,組件非常特別(芬蘭伏特加10毫升),有些則不是(任何伏特加10毫升)。
我不知道如何建模一個組件來解決這個問題 - 庫存我有特定的產品,可以滿足更多的需求。
模型現在是:
class Receipt(models.Model):
name = models.CharField(max_length=128)
(...)
components = models.ManyToManyField(Product, through='ReceiptComponent')
def __unicode__(self):
return self.name
class ReceiptComponent(models.Model):
product = models.ForeignKey(Product)
receipt = models.ForeignKey(Receipt)
quantity = models.FloatField(max_length=9)
unit = models.ForeignKey(Unit)
class Admin:
pass
def __unicode__(self):
return unicode(self.quantity!=0 and self.quantity or '') + ' ' + unicode(self.unit) + ' ' + self.product.genitive
class Product(models.Model):
name = models.CharField(max_length = 128)
(...)
class Admin:
pass
def __unicode__(self):
return self.name
class Stock(Store):
products = models.ManyToManyField(Product)
class Admin:
pass
def __unicode__(self):
return self.name
我想想做一些表,加入真正的產品(股票)與抽象產品(receiptcomponent)。但也許有簡單的解決方案?
這真的很酷的應用程序。在我的情況下完美。謝謝! – 2010-06-11 09:45:51