我正在尝试使用 django-shop 为在线商店创建产品模型。每个产品可能有多种颜色和尺寸,并且产品-颜色-尺寸组合的数量可能不同,因此我创建了另一个颜色-尺寸-数量模型。
如何使我的 GoodsDetail 表中的数据作为 Goods 实例子类化 Product 的一部分?这样我就可以将整个 caboodle 添加到购物车中。
这是我的代码:
from shop.models import Product
from django.db import models
class Category(models.Model):
#some code for Category
class Image(models.Model):
#some code for Image
class Size(models.Model):
#some code for Size
class Manufacturer(models.Model):
#some code for Manufacturer
class Goods(Product):
#name = Product.name
#unit_price = Product.unit_price
category = models.ForeignKey(Category)
serial_n = models.CharField(max_length=20)
manufact = models.ForeignKey(Manufacturer, default=1, null=False, blank=True)
short_decription = models.TextField(max_length=50, default='', blank=True)
long_decription = models.TextField(max_length=250, default='', blank=True)
class Meta:
ordering = ['unit_price']
def __unicode__(self):
return self.name
class ProductAttribute(models.Model):
#some code for an optional attribute
class GoodsDetail(models.Model):
goods = models.ForeignKey(Goods)
COLOUR_CHOICES = (
(u'blue', 'blue'),
(u'green', 'green'),
)
colour = models.CharField(max_length=3, default='', choices=COLOUR_CHOICES)
size = models.ForeignKey(Size, default='', blank = True)
quantity = models.IntegerField(max_length=3, default=0)
image = models.ForeignKey(Image, null=True, blank=True)
attribute = models.ForeignKey('ProductAttribute', null=True, blank = True)
class Meta:
unique_together = [
["goods", "colour", "size"],
]