如何创建django-shop中的产品属性

时间:2017-06-11 13:52:39

标签: django-shop

我喜欢django-shop如何通过开发产品模型来创建新产品属性。例如:SmartPhone ...我想以同样的方式添加产品属性,但我不知道从哪里开始。根据经验,当我从应用程序复制代码时,我最终删除了应用程序,因为它无法正常工作。

我的产品型号是:

`class Product(models.Model):
     name = models.CharField('name', max_length=32)
     slug = models.SlugField('slug', max_length=32)
     description = models.TextField('description')

     class Meta:
          ordering = ['name']`

如果您可以就如何添加类似产品属性向我提出建议,那就太棒了。这样我可以像这个例子一样创建属性。我不想复制所有的应用程序,因为有很多我不需要的东西。 [智能卡示例] [1] https://github.com/awesto/django-shop/tree/master/example/myshop/models

1 个答案:

答案 0 :(得分:0)

首先,您必须决定是否需要多态方法。我认为你的产品变化不大,因此你不需要多态性。

因此,智能卡示例等内容应该足够了:

from shop.money.fields import MoneyField
from shop.models.product import BaseProduct, BaseProductManager, CMSPageReferenceMixin
from shop.models.defaults.mapping import ProductPage, ProductImage

class Product(CMSPageReferenceMixin, BaseProduct):
    # common product fields
    product_name = models.CharField(max_length=32)

    slug = models.SlugField()

    unit_price = MoneyField(decimal_places=3)

    description = models.TextField("Description")

    objects = BaseProductManager()