【问题标题】:How to create products attributes like the one in django-shop如何在 django-shop 中创建产品属性
【发布时间】:2017-11-13 01:19:20
【问题描述】:

我喜欢 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

【问题讨论】:

    标签: django-shop


    【解决方案1】:

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

    因此,例如智能卡示例就足够了:

    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()
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 2019-11-27
      • 1970-01-01
      • 2014-02-10
      • 1970-01-01
      • 2021-06-19
      • 2021-06-05
      • 1970-01-01
      相关资源
      最近更新 更多