跳转到主要内容

一个可扩展的分类应用,用于django-shop,使用django-mptt

项目描述

一个使用django-mptt扩展django-shop分类的应用。

https://travis-ci.org/fivethreeo/django-shop-categories.png?branch=master

安装

对于当前稳定版本

pip install django-shop-categories

对于开发版本

pip install -e git+git://github.com/fivethreeo/django-shop-categories.git#egg=django-shop-categories

运行测试

git clone git://github.com/fivethreeo/django-shop-categories.git
cd django-shop-categories
virtualenv test_env
source ./test_env/bin/activate
pip install -r requirements.txt
python runtests.py

配置

shop_categories 添加到 settings.INSTALLED_APPS

SHOP_PRODUCT_MODEL 设置为 shop_categories.models.defaults.product.default.CategoryProduct

在您的 urls.py 中添加此内容 您的商店模式之前

urlpatterns += patterns('',
    url(r'^catalog/', include('shop_categories.urls')),
)

然后运行

manage.py syncdb

扩展分类模型

在您的应用程序中创建一个带有 __init__.py 和 category.py 目录的 models 目录,如下所示

app/models/__init__.py
app/models/category.py

注意:不要在 __init__.py 中从 category.py 导入模型,模型不应该在一个“真实”的 models 模块中,因为这会导致重写的 Category 模型被定义两次。

在 category.py 中

from django.db import models
from shop_categories.models.defaults.category.base import ProductCategoryBase

class Category(ProductCategoryBase):

    image = models.ImageField(upload_to='categoryimages/', null=True, blank=True)

    class Meta:
        abstract = False
        app_label = 'app'

SHOP_CATEGORIES_CATEGORY_MODEL 设置为 app.models.category.Category

在 admin.py 中注册您的自定义分类模型

from shop_categories.models import Category
from shop_categories.admin import ProductCategoryAdmin

admin.site.register(Category, ProductCategoryAdmin)

然后,假设您的 Product 模型尚未同步,运行

manage.py syncdb

扩展产品模型

当在您的商店中扩展 Product 模型时,请确保它们从 shop_categories.models.defaults.product.base.CategoryProductBase 继承,以添加分类外键和 M2M 字段。

示例实现

可以在此处找到django-shop与django-shop-categories的示例: https://github.com/fivethreeo/django-shop-example

项目详情


下载文件

下载适用于您平台的文件。如果您不确定选择哪个,请了解有关安装包的更多信息。

源分布

django-shop-categories-1.0.zip (17.6 kB 查看哈希值)

上传时间

由以下支持