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"],
]