如何创建像 django-shop 中的产品属性
How to create products attributes like the one in django-shop
我喜欢 django-shop 通过开发产品模型来创建新产品属性的方式。例如:智能手机...我想以同样的方式添加产品属性,但我不知道从哪里开始。根据经验,当我从应用程序复制代码时,我最终会删除该应用程序,因为它无法正常工作。
我的产品型号是:
`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
首先,您必须决定是否需要多态方法。我假设您的产品变化不大,因此您不需要多态性。
因此,诸如智能卡示例之类的东西就足够了:
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()
我喜欢 django-shop 通过开发产品模型来创建新产品属性的方式。例如:智能手机...我想以同样的方式添加产品属性,但我不知道从哪里开始。根据经验,当我从应用程序复制代码时,我最终会删除该应用程序,因为它无法正常工作。
我的产品型号是:
`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
首先,您必须决定是否需要多态方法。我假设您的产品变化不大,因此您不需要多态性。
因此,诸如智能卡示例之类的东西就足够了:
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()