01 | Django REST framework+Vue 生鲜超市 ——表设计和数据录入
Vue环境搭建
(1)node.js
https://nodejs.org/en/
(2)cnpm
npm install -g cnpm --registry=https://registry.npm.taobao.org
(3)安装依赖
cnpm install
(4)运行
cnpm run dev
进虚拟环境下安装
pip install django==1.11.11 pip install djangorestframework pip install -i https://pypi.douban.com/simple django==2.0.2 pip install markdown pip install django-filter pip install pillow # 图片处理 pip install pymysql
项目目录结构搭建
新建两个python package
- extra_apps (扩展的源码包)
- apps (放所有app)
新建两个文件夹
- media (保存图片)
- db_tools (数据库相关)
创建4个app
users 用户 goods 商品 trade 交易 user_operation 用户操作
把四个app、xadmin和DjangoUeditor添加到 INSTALLED_APPS中
INSTALLED_APPS = [ 'django.contrib.auth', 'django.contrib.contenttypes', 'django.contrib.sessions', 'django.contrib.messages', 'django.contrib.staticfiles', 'users.apps.UsersConfig', 'goods.apps.GoodsConfig', 'trade.apps.TradeConfig', 'user_operation.apps.UserOperationConfig', 'rest_framework', 'xadmin', 'crispy_forms', 'DjangoUeditor' ]
把extra_apps和apps标记为sources root,然后settings中也要加路径
#settings.py import sys sys.path.insert(0,BASE_DIR) sys.path.insert(0,os.path.join(BASE_DIR, 'apps')) sys.path.insert(0,os.path.join(BASE_DIR, 'extra_apps'))
设置media的保存路径
#settings.py MEDIA_ROOT = os.path.join(BASE_DIR, "media")
目录如下
数据库的模型设计
users models设计
from datetime import datetime from django.db import models from django.contrib.auth.models import AbstractUser # Create your models here. class UserProfile(AbstractUser): """ 用户 """ name = models.CharField(max_length=30, null=True, blank=True, verbose_name="姓名") birthday = models.DateField(null=True, blank=True, verbose_name="出生年月") gender = models.CharField(max_length=6, choices=(("male", u"男"), ("female", "女")), default="female", verbose_name="性别") mobile = models.CharField(null=True, blank=True, max_length=11, verbose_name="电话") email = models.EmailField(max_length=100, null=True, blank=True, verbose_name="邮箱") class Meta: verbose_name = "用户" verbose_name_plural = verbose_name def __str__(self): return self.username class VerifyCode(models.Model): """ 短信验证码 """ code = models.CharField(max_length=10, verbose_name="验证码") mobile = models.CharField(max_length=11, verbose_name="电话") add_time = models.DateTimeField(default=datetime.now, verbose_name="添加时间") class Meta: verbose_name = "短信验证码" verbose_name_plural = verbose_name def __str__(self): return self.code
要想替换系统的用户,还要在settings中配置
#settings.py #重载系统的用户,让UserProfile生效 AUTH_USER_MODEL = 'users.UserProfile'
商品分类表
商品表
首页商品轮播图表
from datetime import datetime from django.db import models from DjangoUeditor.models import UEditorField # Create your models here. class GoodsCategory(models.Model): """ 商品类别 """ CATEGORY_TYPE = ( (1, "一级类目"), (2, "二级类目"), (3, "三级类目"), ) name = models.CharField(default="", max_length=30, verbose_name="类别名", help_text="类别名") code = models.CharField(default="", max_length=30, verbose_name="类别code", help_text="类别code") desc = models.TextField(default="", verbose_name="类别描述", help_text="类别描述") category_type = models.IntegerField(choices=CATEGORY_TYPE, verbose_name="类目级别", help_text="类目级别") parent_category = models.ForeignKey("self", null=True, blank=True, verbose_name="父类目级别", help_text="父目录", related_name="sub_cat") is_tab = models.BooleanField(default=False, verbose_name="是否导航", help_text="是否导航") add_time = models.DateTimeField(default=datetime.now, verbose_name="添加时间") class Meta: verbose_name = "商品类别" verbose_name_plural = verbose_name def __str__(self): return self.name class GoodsCategoryBrand(models.Model): """ 品牌名 """ category = models.ForeignKey(GoodsCategory, related_name='brands', null=True, blank=True, verbose_name="商品类目") name = models.CharField(default="", max_length=30, verbose_name="品牌名", help_text="品牌名") desc = models.TextField(default="", max_length=200, verbose_name="品牌描述", help_text="品牌描述") image = models.ImageField(max_length=200, upload_to="brands/") add_time = models.DateTimeField(default=datetime.now, verbose_name="添加时间") class Meta: verbose_name = "品牌" verbose_name_plural = verbose_name db_table = "goods_goodsbrand" def __str__(self): return self.name class Goods(models.Model): """ 商品 """ category = models.ForeignKey(GoodsCategory, verbose_name="商品类目") goods_sn = models.CharField(max_length=50, default="", verbose_name="商品唯一货号") name = models.CharField(max_length=100, verbose_name="商品名") click_num = models.IntegerField(default=0, verbose_name="点击数") sold_num = models.IntegerField(default=0, verbose_name="商品销售量") fav_num = models.IntegerField(default=0, verbose_name="收藏数") goods_num = models.IntegerField(default=0, verbose_name="库存数") market_price = models.FloatField(default=0, verbose_name="市场价格") shop_price = models.FloatField(default=0, verbose_name="本店价格") goods_brief = models.TextField(max_length=500, verbose_name="商品简短描述") goods_desc = UEditorField(verbose_name=u"内容", imagePath="goods/images/", width=1000, height=300, filePath="goods/files/", default='') ship_free = models.BooleanField(default=True, verbose_name="是否承担运费") goods_front_image = models.ImageField(upload_to="goods/images/", null=True, blank=True, verbose_name="封面图") is_new = models.BooleanField(default=False, verbose_name="是否新品") is_hot = models.BooleanField(default=False, verbose_name="是否热销") add_time = models.DateTimeField(default=datetime.now, verbose_name="添加时间") class Meta: verbose_name = '商品' verbose_name_plural = verbose_name def __str__(self): return self.name class IndexAd(models.Model): category = models.ForeignKey(GoodsCategory, related_name='category',verbose_name="商品类目") goods =models.ForeignKey(Goods, related_name='goods') class Meta: verbose_name = '首页商品类别广告' verbose_name_plural = verbose_name def __str__(self): return self.goods.name class GoodsImage(models.Model): """ 商品轮播图 """ goods = models.ForeignKey(Goods, verbose_name="商品", related_name="images") image = models.ImageField(upload_to="", verbose_name="图片", null=True, blank=True) add_time = models.DateTimeField(default=datetime.now, verbose_name="添加时间") class Meta: verbose_name = '商品图片' verbose_name_plural = verbose_name def __str__(self): return self.goods.name class Banner(models.Model): """ 轮播的商品 """ goods = models.ForeignKey(Goods, verbose_name="商品") image = models.ImageField(upload_to='banner', verbose_name="轮播图片") index = models.IntegerField(default=0, verbose_name="轮播顺序") add_time = models.DateTimeField(default=datetime.now, verbose_name="添加时间") class Meta: verbose_name = '轮播商品' verbose_name_plural = verbose_name def __str__(self): return self.goods.name class HotSearchWords(models.Model): """ 热搜词 """ keywords = models.CharField(default="", max_length=20, verbose_name="热搜词") index = models.IntegerField(default=0, verbose_name="排序") add_time = models.DateTimeField(default=datetime.now, verbose_name="添加时间") class Meta: verbose_name = '热搜词' verbose_name_plural = verbose_name def __str__(self): return self.keywords
trade交易的model设计
from datetime import datetime from django.db import models from django.contrib.auth import get_user_model from goods.models import Goods User = get_user_model() # Create your models here. class ShoppingCart(models.Model): """ 购物车 """ user = models.ForeignKey(User, verbose_name=u"用户") goods = models.ForeignKey(Goods, verbose_name=u"商品") nums = models.IntegerField(default=0, verbose_name="购买数量") add_time = models.DateTimeField(default=datetime.now, verbose_name=u"添加时间") class Meta: verbose_name = '购物车' verbose_name_plural = verbose_name unique_together = ("user", "goods") def __str__(self): return "%s(%d)".format(self.goods.name, self.nums) class OrderInfo(models.Model): """ 订单 """ ORDER_STATUS = ( ("TRADE_SUCCESS", "成功"), ("TRADE_CLOSED", "超时关闭"), ("WAIT_BUYER_PAY", "交易创建"), ("TRADE_FINISHED", "交易结束"), ("paying", "待支付"), ) user = models.ForeignKey(User, verbose_name="用户") order_sn = models.CharField(max_length=30, null=True, blank=True, unique=True, verbose_name="订单号") trade_no = models.CharField(max_length=100, unique=True, null=True, blank=True, verbose_name=u"交易号") pay_status = models.CharField(choices=ORDER_STATUS, default="paying", max_length=30, verbose_name="订单状态") post_script = models.CharField(max_length=200, verbose_name="订单留言") order_mount = models.FloatField(default=0.0, verbose_name="订单金额") pay_time = models.DateTimeField(null=True, blank=True, verbose_name="支付时间") # 用户信息 address = models.CharField(max_length=100, default="", verbose_name="收货地址") signer_name = models.CharField(max_length=20, default="", verbose_name="签收人") singer_mobile = models.CharField(max_length=11, verbose_name="联系电话") add_time = models.DateTimeField(default=datetime.now, verbose_name="添加时间") class Meta: verbose_name = u"订单" verbose_name_plural = verbose_name def __str__(self): return str(self.order_sn) class OrderGoods(models.Model): """ 订单的商品详情 """ order = models.ForeignKey(OrderInfo, verbose_name="订单信息", related_name="goods") goods = models.ForeignKey(Goods, verbose_name="商品") goods_num = models.IntegerField(default=0, verbose_name="商品数量") add_time = models.DateTimeField(default=datetime.now, verbose_name="添加时间") class Meta: verbose_name = "订单商品" verbose_name_plural = verbose_name def __str__(self): return str(self.order.order_sn)
用户操作的model设计
from datetime import datetime from django.db import models from django.contrib.auth import get_user_model from goods.models import Goods # Create your models here. User = get_user_model() class UserFav(models.Model): """ 用户收藏 """ user = models.ForeignKey(User, verbose_name="用户") goods = models.ForeignKey(Goods, verbose_name="商品", help_text="商品id") add_time = models.DateTimeField(default=datetime.now, verbose_name=u"添加时间") class Meta: verbose_name = '用户收藏' verbose_name_plural = verbose_name unique_together = ("user", "goods") def __str__(self): return self.user.username class UserLeavingMessage(models.Model): """ 用户留言 """ MESSAGE_CHOICES = ( (1, "留言"), (2, "投诉"), (3, "询问"), (4, "售后"), (5, "求购") ) user = models.ForeignKey(User, verbose_name="用户") message_type = models.IntegerField(default=1, choices=MESSAGE_CHOICES, verbose_name="留言类型", help_text=u"留言类型: 1(留言),2(投诉),3(询问),4(售后),5(求购)") subject = models.CharField(max_length=100, default="", verbose_name="主题") message = models.TextField(default="", verbose_name="留言内容", help_text="留言内容") file = models.FileField(upload_to="message/images/", verbose_name="上传的文件", help_text="上传的文件") add_time = models.DateTimeField(default=datetime.now, verbose_name="添加时间") class Meta: verbose_name = "用户留言" verbose_name_plural = verbose_name def __str__(self): return self.subject class UserAddress(models.Model): """ 用户收货地址 """ user = models.ForeignKey(User, verbose_name="用户" ) province = models.CharField(max_length=100, default="", verbose_name="省份") city = models.CharField(max_length=100, default="", verbose_name="城市") district = models.CharField(max_length=100, default="", verbose_name="区域") address = models.CharField(max_length=100, default="", verbose_name="详细地址") signer_name = models.CharField(max_length=100, default="", verbose_name="签收人") signer_mobile = models.CharField(max_length=11, default="", verbose_name="电话") add_time = models.DateTimeField(default=datetime.now, verbose_name="添加时间") class Meta: verbose_name = "收货地址" verbose_name_plural = verbose_name def __str__(self): return self.address
设置时区和配置中文
LANGUAGE_CODE = 'zh-hans' #中文支持,django1.8以后支持;1.8以前是zh-cn TIME_ZONE = 'Asia/Shanghai' USE_I18N = True USE_L10N = True USE_TZ = False #默认是Ture,时间是utc时间,由于我们要用本地时间,所用手动修改为false!!!!
图片存放路径配置
MEDIA_URL = "/media/" STATICFILES_DIRS = ( os.path.join(BASE_DIR, "static"), ) MEDIA_ROOT = os.path.join(BASE_DIR, "media")
xadmin配置
在 extra_apps 报下放入源码文件
- xadmin
- DjangoUeditor
xadmin安装依赖
pip install django-crispy-forms pip install django-reversion pip install django-formtools pip install future pip install httplib2 pip install six pip install xlwt pip install xlsxwriter
配置xadmin 分别在各自的应用下添加以下代码
#!/usr/bin/env python # encoding: utf-8 """ @version: 1.0 @author: liyao @license: Apache Licence @contact: yli@posbao.net @site: http://www.piowind.com/ @software: PyCharm @file: adminx.py @time: 2017/7/4 17:04 """ import xadmin from .models import Goods, GoodsCategory, GoodsImage, GoodsCategoryBrand, Banner, HotSearchWords from .models import IndexAd class GoodsAdmin(object): list_display = ["name", "click_num", "sold_num", "fav_num", "goods_num", "market_price", "shop_price", "goods_brief", "goods_desc", "is_new", "is_hot", "add_time"] search_fields = ['name', ] list_editable = ["is_hot", ] list_filter = ["name", "click_num", "sold_num", "fav_num", "goods_num", "market_price", "shop_price", "is_new", "is_hot", "add_time", "category__name"] style_fields = {"goods_desc": "ueditor"} class GoodsImagesInline(object): model = GoodsImage exclude = ["add_time"] extra = 1 style = 'tab' inlines = [GoodsImagesInline] class GoodsCategoryAdmin(object): list_display = ["name", "category_type", "parent_category", "add_time"] list_filter = ["category_type", "parent_category", "name"] search_fields = ['name', ] class GoodsBrandAdmin(object): list_display = ["category", "image", "name", "desc"] def get_context(self): context = super(GoodsBrandAdmin, self).get_context() if 'form' in context: context['form'].fields['category'].queryset = GoodsCategory.objects.filter(category_type=1) return context class BannerGoodsAdmin(object): list_display = ["goods", "image", "index"] class HotSearchAdmin(object): list_display = ["keywords", "index", "add_time"] class IndexAdAdmin(object): list_display = ["category", "goods"] xadmin.site.register(Goods, GoodsAdmin) xadmin.site.register(GoodsCategory, GoodsCategoryAdmin) xadmin.site.register(Banner, BannerGoodsAdmin) xadmin.site.register(GoodsCategoryBrand, GoodsBrandAdmin) xadmin.site.register(HotSearchWords, HotSearchAdmin) xadmin.site.register(IndexAd, IndexAdAdmin)
# -*- coding: utf-8 -*- __author__ = 'bobby' import xadmin from .models import ShoppingCart, OrderInfo, OrderGoods class ShoppingCartAdmin(object): list_display = ["user", "goods", "nums", ] class OrderInfoAdmin(object): list_display = ["user", "order_sn", "trade_no", "pay_status", "post_script", "order_mount", "order_mount", "pay_time", "add_time"] class OrderGoodsInline(object): model = OrderGoods exclude = ['add_time', ] extra = 1 style = 'tab' inlines = [OrderGoodsInline, ] xadmin.site.register(ShoppingCart, ShoppingCartAdmin) xadmin.site.register(OrderInfo, OrderInfoAdmin)
#!/usr/bin/env python # encoding: utf-8 """ @version: 1.0 @author: liyao @license: Apache Licence @contact: yli@posbao.net @site: http://www.piowind.com/ @software: PyCharm @file: adminx.py @time: 2017/7/4 17:04 """ import xadmin from .models import UserFav, UserLeavingMessage, UserAddress class UserFavAdmin(object): list_display = ['user', 'goods', "add_time"] class UserLeavingMessageAdmin(object): list_display = ['user', 'message_type', "message", "add_time"] class UserAddressAdmin(object): list_display = ["signer_name", "signer_mobile", "district", "address"] xadmin.site.register(UserFav, UserFavAdmin) xadmin.site.register(UserAddress, UserAddressAdmin) xadmin.site.register(UserLeavingMessage, UserLeavingMessageAdmin)
#!/usr/bin/env python # encoding: utf-8 """ @version: 1.0 @author: liyao @license: Apache Licence @contact: yli@posbao.net @site: http://www.piowind.com/ @software: PyCharm @file: adminx.py @time: 2017/7/4 17:04 """ import xadmin from xadmin import views from .models import VerifyCode class BaseSetting(object): enable_themes = True use_bootswatch = True class GlobalSettings(object): site_title = "慕学生鲜后台" site_footer = "mxshop" # menu_style = "accordion" class VerifyCodeAdmin(object): list_display = ['code', 'mobile', "add_time"] xadmin.site.register(VerifyCode, VerifyCodeAdmin) xadmin.site.register(views.BaseAdminView, BaseSetting) xadmin.site.register(views.CommAdminView, GlobalSettings)
把xadmin注册到app中
配置xadmin访问路径,在跟路由中填写以下配置
import xadmin from MxShop.settings import MEDIA_ROOT from django.views.static import serve urlpatterns = [ url(r'^admin/', xadmin.site.urls), url(r'^media/(?P<path>.*)$', serve, {"document_root": MEDIA_ROOT}), ]
录入数据
在media目录下放入要录入的图片
在db_tool目录下创建以下文件
代码如下
#!/usr/bin/env python # encoding: utf-8 row_data = [ { 'sub_categorys': [ { 'sub_categorys': [ { 'code': 'yr', 'name': '羊肉' }, { 'code': 'ql', 'name': '禽类' }, { 'code': 'zr', 'name': '猪肉' }, { 'code': 'nr', 'name': '牛肉' } ], 'code': 'jprl', 'name': '精品肉类' }, { 'sub_categorys': [ { 'code': 'cb', 'name': '参鲍' }, { 'code': 'yu', 'name': '鱼' }, { 'code': 'xia', 'name': '虾' }, { 'code': 'xb', 'name': '蟹/贝' } ], 'code': 'hxsc', 'name': '海鲜水产' }, { 'sub_categorys': [ { 'code': 'xhd_xyd', 'name': '松花蛋/咸鸭蛋' }, { 'code': 'jd', 'name': '鸡蛋' } ], 'code': 'dzp', 'name': '蛋制品' }, { 'sub_categorys': [ { 'code': 'sc', 'name': '生菜' }, { 'code': 'bc', 'name': '菠菜' }, { 'code': 'yj', 'name': '圆椒' }, { 'code': 'xlh', 'name': '西兰花' } ], 'code': 'ycl', 'name': '叶菜类' }, { 'sub_categorys': [ ], 'code': 'gjl', 'name': '根茎类' }, { 'sub_categorys': [ ], 'code': 'qgl', 'name': '茄果类' }, { 'sub_categorys': [ ], 'code': 'jgl', 'name': '菌菇类' }, { 'sub_categorys': [ ], 'code': 'jksx', 'name': '进口生鲜' } ], 'code': 'sxsp', 'name': '生鲜食品' }, { 'sub_categorys': [ { 'sub_categorys': [ { 'code': 'wly', 'name': '五粮液' }, { 'code': 'lzlj', 'name': '泸州老窖' }, { 'code': 'mt', 'name': '茅台' } ], 'code': 'bk', 'name': '白酒' }, { 'sub_categorys': [ ], 'code': 'ptj', 'name': '葡萄酒' }, { 'sub_categorys': [ ], 'code': 'yj', 'name': '洋酒' }, { 'sub_categorys': [ ], 'code': 'pj', 'name': '啤酒' }, { 'sub_categorys': [ { 'code': 'qtpp', 'name': '其他品牌' }, { 'code': 'hj', 'name': '黄酒' }, { 'code': 'ysj', 'name': '养生酒' } ], 'code': 'qtjp', 'name': '其他酒品' }, { 'sub_categorys': [ ], 'code': 'yls', 'name': '饮料/水' }, { 'sub_categorys': [ { 'code': 'bld', 'name': '白兰地' }, { 'code': 'wsj', 'name': '威士忌' } ], 'code': 'hj', 'name': '红酒' } ], 'code': 'jsyl', 'name': '酒水饮料' }, { 'sub_categorys': [ { 'sub_categorys': [ { 'code': '其他食用油', 'name': '其他食用油' }, { 'code': '菜仔油', 'name': '菜仔油' }, { 'code': '花生油', 'name': '花生油' }, { 'code': '橄榄油', 'name': '橄榄油' }, { 'code': '礼盒', 'name': '礼盒' } ], 'code': '食用油', 'name': '食用油' }, { 'sub_categorys': [ { 'code': '面粉/面条', 'name': '面粉/面条' }, { 'code': '大米', 'name': '大米' }, { 'code': '意大利面', 'name': '意大利面' } ], 'code': '米面杂粮', 'name': '米面杂粮' }, { 'sub_categorys': [ { 'code': '调味油/汁', 'name': '调味油/汁' }, { 'code': '酱油/醋', 'name': '酱油/醋' } ], 'code': '厨房调料', 'name': '厨房调料' }, { 'sub_categorys': [ ], 'code': '南北干货', 'name': '南北干货' }, { 'sub_categorys': [ ], 'code': '方便速食', 'name': '方便速食' }, { 'sub_categorys': [ ], 'code': '调味品', 'name': '调味品' } ], 'code': '粮油副食', 'name': '粮油副食' }, { 'sub_categorys': [ { 'sub_categorys': [ { 'code': '西红柿', 'name': '西红柿' }, { 'code': '韭菜', 'name': '韭菜' }, { 'code': '青菜', 'name': '青菜' } ], 'code': '有机蔬菜', 'name': '有机蔬菜' }, { 'sub_categorys': [ { 'code': '甘蓝', 'name': '甘蓝' }, { 'code': '胡萝卜', 'name': '胡萝卜' }, { 'code': '黄瓜', 'name': '黄瓜' } ], 'code': '精选蔬菜', 'name': '精选蔬菜' }, { 'sub_categorys': [ { 'code': '火龙果', 'name': '火龙果' }, { 'code': '菠萝蜜', 'name': '菠萝蜜' }, { 'code': '奇异果', 'name': '奇异果' } ], 'code': '进口水果', 'name': '进口水果' }, { 'sub_categorys': [ { 'code': '水果礼盒', 'name': '水果礼盒' }, { 'code': '苹果', 'name': '苹果' }, { 'code': '雪梨', 'name': '雪梨' } ], 'code': '国产水果', 'name': '国产水果' } ], 'code': '蔬菜水果', 'name': '蔬菜水果' }, { 'sub_categorys': [ { 'sub_categorys': [ { 'code': '果冻', 'name': '果冻' }, { 'code': '枣类', 'name': '枣类' }, { 'code': '蜜饯', 'name': '蜜饯' }, { 'code': '肉类零食', 'name': '肉类零食' }, { 'code': '坚果炒货', 'name': '坚果炒货' } ], 'code': '休闲零食', 'name': '休闲零食' }, { 'sub_categorys': [ { 'code': '创意喜糖', 'name': '创意喜糖' }, { 'code': '口香糖', 'name': '口香糖' }, { 'code': '软糖', 'name': '软糖' }, { 'code': '棒棒糖', 'name': '棒棒糖' } ], 'code': '糖果', 'name': '糖果' }, { 'sub_categorys': [ { 'code': '夹心巧克力', 'name': '夹心巧克力' }, { 'code': '白巧克力', 'name': '白巧克力' }, { 'code': '松露巧克力', 'name': '松露巧克力' }, { 'code': '黑巧克力', 'name': '黑巧克力' } ], 'code': '巧克力', 'name': '巧克力' }, { 'sub_categorys': [ { 'code': '牛肉干', 'name': '牛肉干' }, { 'code': '猪肉脯', 'name': '猪肉脯' }, { 'code': '牛肉粒', 'name': '牛肉粒' }, { 'code': '猪肉干', 'name': '猪肉干' } ], 'code': '肉干肉脯/豆干', 'name': '肉干肉脯/豆干' }, { 'sub_categorys': [ { 'code': '鱿鱼足', 'name': '鱿鱼足' }, { 'code': '鱿鱼丝', 'name': '鱿鱼丝' }, { 'code': '墨鱼/乌贼', 'name': '墨鱼/乌贼' }, { 'code': '鱿鱼仔', 'name': '鱿鱼仔' }, { 'code': '鱿鱼片', 'name': '鱿鱼片' } ], 'code': '鱿鱼丝/鱼干', 'name': '鱿鱼丝/鱼干' } ], 'code': '休闲食品', 'name': '休闲食品' }, { 'sub_categorys': [ { 'sub_categorys': [ ], 'code': '进口奶品', 'name': '进口奶品' }, { 'sub_categorys': [ ], 'code': '国产奶品', 'name': '国产奶品' }, { 'sub_categorys': [ ], 'code': '奶粉', 'name': '奶粉' }, { 'sub_categorys': [ ], 'code': '有机奶', 'name': '有机奶' }, { 'sub_categorys': [ ], 'code': '原料奶', 'name': '原料奶' } ], 'code': '奶类食品', 'name': '奶类食品' }, { 'sub_categorys': [ { 'sub_categorys': [ ], 'code': '菌菇类', 'name': '菌菇类' }, { 'sub_categorys': [ ], 'code': '腌干海产', 'name': '腌干海产' }, { 'sub_categorys': [ ], 'code': '汤料', 'name': '汤料' }, { 'sub_categorys': [ ], 'code': '豆类', 'name': '豆类' }, { 'sub_categorys': [ ], 'code': '干菜/菜干', 'name': '干菜/菜干' }, { 'sub_categorys': [ ], 'code': '干果/果干', 'name': '干果/果干' }, { 'sub_categorys': [ ], 'code': '豆制品', 'name': '豆制品' }, { 'sub_categorys': [ ], 'code': '腊味', 'name': '腊味' } ], 'code': '天然干货', 'name': '天然干货' }, { 'sub_categorys': [ { 'sub_categorys': [ ], 'code': '白茶', 'name': '白茶' }, { 'sub_categorys': [ ], 'code': '红茶', 'name': '红茶' }, { 'sub_categorys': [ ], 'code': '绿茶', 'name': '绿茶' } ], 'code': '精选茗茶', 'name': '精选茗茶' } ]
#!/usr/bin/env python # encoding: utf-8 row_data = [ { 'images': [ 'goods/images/1_P_1449024889889.jpg', 'goods/images/1_P_1449024889264.jpg', 'goods/images/1_P_1449024889726.jpg', 'goods/images/1_P_1449024889018.jpg', 'goods/images/1_P_1449024889287.jpg' ], 'categorys': [ '首页', '生鲜食品', '根茎类' ], 'market_price': '¥232元', 'name': '新鲜水果甜蜜香脆单果约800克', 'desc': '食用百香果可以增加胃部饱腹感,减少余热量的摄入,还可以吸附胆固醇和胆汁之类有机分子,抑制人体对脂肪的吸收。因此,长期食用有利于改善人体营养吸收结构,降低体内脂肪,塑造健康优美体态。', 'sale_price': '¥156元', 'goods_desc':'<p><img src="/media/goods/images/2_20170719161405_249.jpg" title="" alt="2.jpg"/></p><p><img src="/media/goods/images/2_20170719161414_628.jpg" title="" alt="2.jpg"/></p><p><img src="/media/goods/images/2_20170719161435_381.jpg" title="" alt="2.jpg"/></p>' }, { 'images': [ 'goods/images/2_P_1448945810202.jpg', 'goods/images/2_P_1448945810814.jpg' ], 'categorys': [ '首页', '生鲜食品', '海鲜水产' ], 'market_price': '¥106元', 'name': '田然牛肉大黄瓜条生鲜牛肉冷冻真空黄牛', 'desc': '前腿+后腿+羊排共8斤,原生态大山放牧羊羔,曾经的皇室贡品,央视推荐,2005年北京招待全球财金首脑。五层专用包装箱+真空包装+冰袋+保鲜箱+顺丰冷链发货,路途保质期8天', 'sale_price': '¥88元', 'goods_desc':'<p><img src="/media/goods/images/2_20170719161405_249.jpg" title="" alt="2.jpg"/></p><p><img src="/media/goods/images/2_20170719161414_628.jpg" title="" alt="2.jpg"/></p><p><img src="/media/goods/images/2_20170719161435_381.jpg" title="" alt="2.jpg"/></p>' }, { 'images': [ 'goods/images/7_P_1448945104883.jpg', 'goods/images/7_P_1448945104734.jpg' ], 'categorys': [ '首页', '生鲜食品', '叶菜类' ], 'market_price': '¥286元', 'name': '酣畅家庭菲力牛排10片澳洲生鲜牛肉团购套餐', 'desc': None, 'sale_price': '¥238元', 'goods_desc':'<p><img src="/media/goods/images/2_20170719161405_249.jpg" title="" alt="2.jpg"/></p><p><img src="/media/goods/images/2_20170719161414_628.jpg" title="" alt="2.jpg"/></p><p><img src="/media/goods/images/2_20170719161435_381.jpg" title="" alt="2.jpg"/></p>' }, { 'images': [ 'goods/images/47_P_1448946213263.jpg', 'goods/images/47_P_1448946213157.jpg' ], 'categorys': [ '首页', '生鲜食品', '根茎类' ], 'market_price': '¥156元', 'name': '日本蒜蓉粉丝扇贝270克6只装', 'desc': None, 'sale_price': '¥108元', 'goods_desc':'<p><img src="/media/goods/images/2_20170719161405_249.jpg" title="" alt="2.jpg"/></p><p><img src="/media/goods/images/2_20170719161414_628.jpg" title="" alt="2.jpg"/></p><p><img src="/media/goods/images/2_20170719161435_381.jpg" title="" alt="2.jpg"/></p>' }, { 'images': [ 'goods/images/10_P_1448944572085.jpg', 'goods/images/10_P_1448944572532.jpg', 'goods/images/10_P_1448944572872.jpg' ], 'categorys': [ '首页', '生鲜食品', '海鲜水产' ], 'market_price': '¥106元', 'name': '内蒙新鲜牛肉1斤清真生鲜牛肉火锅食材', 'desc': None, 'sale_price': '¥88元', 'goods_desc':'<p><img src="/media/goods/images/2_20170719161405_249.jpg" title="" alt="2.jpg"/></p><p><img src="/media/goods/images/2_20170719161414_628.jpg" title="" alt="2.jpg"/></p><p><img src="/media/goods/images/2_20170719161435_381.jpg" title="" alt="2.jpg"/></p>' }, { 'images': [ 'goods/images/4_P_1448945381985.jpg', 'goods/images/4_P_1448945381013.jpg' ], 'categorys': [ '首页', '生鲜食品', '茄果类' ], 'market_price': '¥90元', 'name': '乌拉圭进口牛肉卷特级肥牛卷', 'desc': None, 'sale_price': '¥75元', 'goods_desc':'<p><img src="/media/goods/images/2_20170719161405_249.jpg" title="" alt="2.jpg"/></p><p><img src="/media/goods/images/2_20170719161414_628.jpg" title="" alt="2.jpg"/></p><p><img src="/media/goods/images/2_20170719161435_381.jpg" title="" alt="2.jpg"/></p>' }, { 'images': [ 'goods/images/8_P_1448945032810.jpg', 'goods/images/8_P_1448945032646.jpg' ], 'categorys': [ '首页', '生鲜食品', '进口生鲜' ], 'market_price': '¥150元', 'name': '五星眼肉牛排套餐8片装原味原切生鲜牛肉', 'desc': None, 'sale_price': '¥125元', 'goods_desc':'<p><img src="/media/goods/images/2_20170719161405_249.jpg" title="" alt="2.jpg"/></p><p><img src="/media/goods/images/2_20170719161414_628.jpg" title="" alt="2.jpg"/></p><p><img src="/media/goods/images/2_20170719161435_381.jpg" title="" alt="2.jpg"/></p>' }, { 'images': [ 'goods/images/11_P_1448944388277.jpg', 'goods/images/11_P_1448944388034.jpg', 'goods/images/11_P_1448944388201.jpg' ], 'categorys': [ '首页', '生鲜食品', '海鲜水产' ], 'market_price': '¥31元', 'name': '澳洲进口120天谷饲牛仔骨4份原味生鲜', 'desc': None, 'sale_price': '¥26元', 'goods_desc':'<p><img src="/media/goods/images/2_20170719161405_249.jpg" title="" alt="2.jpg"/></p><p><img src="/media/goods/images/2_20170719161414_628.jpg" title="" alt="2.jpg"/></p><p><img src="/media/goods/images/2_20170719161435_381.jpg" title="" alt="2.jpg"/></p>' }, { 'images': [ 'goods/images/6_P_1448945167279.jpg', 'goods/images/6_P_1448945167015.jpg' ], 'categorys': [ '首页', '生鲜食品', '菌菇类' ], 'market_price': '¥239元', 'name': '潮香村澳洲进口牛排家庭团购套餐20片', 'desc': None, 'sale_price': '¥199元', 'goods_desc':'<p><img src="/media/goods/images/2_20170719161405_249.jpg" title="" alt="2.jpg"/></p><p><img src="/media/goods/images/2_20170719161414_628.jpg" title="" alt="2.jpg"/></p><p><img src="/media/goods/images/2_20170719161435_381.jpg" title="" alt="2.jpg"/></p>' }, { 'images': [ 'goods/images/9_P_1448944791617.jpg', 'goods/images/9_P_1448944791129.jpg', 'goods/images/9_P_1448944791077.jpg', 'goods/images/9_P_1448944791229.jpg' ], 'categorys': [ '首页', '生鲜食品', '根茎类' ], 'market_price': '¥202元', 'name': '爱食派内蒙古呼伦贝尔冷冻生鲜牛腱子肉1000g', 'desc': None, 'sale_price': '¥168元', 'goods_desc':'<p><img src="/media/goods/images/2_20170719161405_249.jpg" title="" alt="2.jpg"/></p><p><img src="/media/goods/images/2_20170719161414_628.jpg" title="" alt="2.jpg"/></p><p><img src="/media/goods/images/2_20170719161435_381.jpg" title="" alt="2.jpg"/></p>' }, { 'images': [ 'goods/images/3_P_1448945490837.jpg', 'goods/images/3_P_1448945490084.jpg' ], 'categorys': [ '首页', '生鲜食品', '精品肉类' ], 'market_price': '¥306元', 'name': '澳洲进口牛尾巴300g新鲜肥牛肉', 'desc': '新鲜羊羔肉整只共15斤,原生态大山放牧羊羔,曾经的皇室贡品,央视推荐,2005年北京招待全球财金首脑。五层专用包装箱+真空包装+冰袋+保鲜箱+顺丰冷链发货,路途保质期8天', 'sale_price': '¥255元', 'goods_desc':'<p><img src="/media/goods/images/2_20170719161405_249.jpg" title="" alt="2.jpg"/></p><p><img src="/media/goods/images/2_20170719161414_628.jpg" title="" alt="2.jpg"/></p><p><img src="/media/goods/images/2_20170719161435_381.jpg" title="" alt="2.jpg"/></p>' }, { 'images': [ 'goods/images/48_P_1448943988970.jpg', 'goods/images/48_P_1448943988898.jpg', 'goods/images/48_P_1448943988439.jpg' ], 'categorys': [ '首页', '生鲜食品', '海鲜水产' ], 'market_price': '¥126元', 'name': '新疆巴尔鲁克生鲜牛排眼肉牛扒1200g', 'desc': None, 'sale_price': '¥88元', 'goods_desc':'<p><img src="/media/goods/images/2_20170719161405_249.jpg" title="" alt="2.jpg"/></p><p><img src="/media/goods/images/2_20170719161414_628.jpg" title="" alt="2.jpg"/></p><p><img src="/media/goods/images/2_20170719161435_381.jpg" title="" alt="2.jpg"/></p>' }, { 'images': [ 'goods/images/5_P_1448945270390.jpg', 'goods/images/5_P_1448945270067.jpg', 'goods/images/5_P_1448945270432.jpg' ], 'categorys': [ '首页', '生鲜食品', '蛋制品' ], 'market_price': '¥144元', 'name': '澳洲进口安格斯牛切片上脑牛排1000g', 'desc': '澳大利亚是国际公认的没有疯牛病和口蹄疫的国家。为了保持澳大利亚产品的高标准,澳大利亚牛肉业和各级政府共同努力简历了严格的标准和体系,以保证生产的整体化和产品的可追溯性', 'sale_price': '¥120元', 'goods_desc':'<p><img src="/media/goods/images/2_20170719161405_249.jpg" title="" alt="2.jpg"/></p><p><img src="/media/goods/images/2_20170719161414_628.jpg" title="" alt="2.jpg"/></p><p><img src="/media/goods/images/2_20170719161435_381.jpg" title="" alt="2.jpg"/></p>' }, { 'images': [ 'images/201705/goods_img/53_P_1495068879687.jpg' ], 'categorys': [ '首页', '生鲜食品', '茄果类' ], 'market_price': '¥120元', 'name': '帐篷出租', 'desc': None, 'sale_price': '¥100元', 'goods_desc':'<p><img src="/media/goods/images/2_20170719161405_249.jpg" title="" alt="2.jpg"/></p><p><img src="/media/goods/images/2_20170719161414_628.jpg" title="" alt="2.jpg"/></p><p><img src="/media/goods/images/2_20170719161435_381.jpg" title="" alt="2.jpg"/></p>' }, { 'images': [ 'goods/images/16_P_1448947194687.jpg' ], 'categorys': [ '首页', '酒水饮料', '红酒' ], 'market_price': '¥23元', 'name': '52度茅台集团国隆双喜酒500mlx6', 'desc': '贵州茅台酒厂(集团)保健酒业有限公司生产,是以“龙”字打头的酒水。中国龙文化上下8000年,源远而流长,龙的形象是一种符号、一种意绪、一种血肉相联的情感。', 'sale_price': '¥19元', 'goods_desc':'<p><img src="/media/goods/images/2_20170719161405_249.jpg" title="" alt="2.jpg"/></p><p><img src="/media/goods/images/2_20170719161414_628.jpg" title="" alt="2.jpg"/></p><p><img src="/media/goods/images/2_20170719161435_381.jpg" title="" alt="2.jpg"/></p>' }, { 'images': [ 'goods/images/14_P_1448947354031.jpg', 'goods/images/14_P_1448947354433.jpg' ], 'categorys': [ '首页', '酒水饮料', '饮料/水' ], 'market_price': '¥43元', 'name': '52度水井坊臻酿八號500ml', 'desc': None, 'sale_price': '¥36元', 'goods_desc':'<p><img src="/media/goods/images/2_20170719161405_249.jpg" title="" alt="2.jpg"/></p><p><img src="/media/goods/images/2_20170719161414_628.jpg" title="" alt="2.jpg"/></p><p><img src="/media/goods/images/2_20170719161435_381.jpg" title="" alt="2.jpg"/></p>' }, { 'images': [ 'goods/images/12_P_1448947547989.jpg' ], 'categorys': [ '首页', '酒水饮料', '其他酒品' ], 'market_price': '¥190元', 'name': '53度茅台仁酒500ml', 'desc': None, 'sale_price': '¥158元', 'goods_desc':'<p><img src="/media/goods/images/2_20170719161405_249.jpg" title="" alt="2.jpg"/></p><p><img src="/media/goods/images/2_20170719161414_628.jpg" title="" alt="2.jpg"/></p><p><img src="/media/goods/images/2_20170719161435_381.jpg" title="" alt="2.jpg"/></p>' }, { 'images': [ 'goods/images/46_P_1448946598711.jpg', 'goods/images/46_P_1448946598301.jpg' ], 'categorys': [ '首页', '酒水饮料', '葡萄酒' ], 'market_price': '¥38元', 'name': '双响炮洋酒JimBeamwhiskey美国白占边', 'desc': None, 'sale_price': '¥28元', 'goods_desc':'<p><img src="/media/goods/images/2_20170719161405_249.jpg" title="" alt="2.jpg"/></p><p><img src="/media/goods/images/2_20170719161414_628.jpg" title="" alt="2.jpg"/></p><p><img src="/media/goods/images/2_20170719161435_381.jpg" title="" alt="2.jpg"/></p>' }, { 'images': [ 'goods/images/21_P_1448946793276.jpg', 'goods/images/21_P_1448946793153.jpg' ], 'categorys': [ '首页', '酒水饮料', '饮料/水' ], 'market_price': '¥55元', 'name': '西夫拉姆进口洋酒小酒版', 'desc': None, 'sale_price': '¥46元', 'goods_desc':'<p><img src="/media/goods/images/2_20170719161405_249.jpg" title="" alt="2.jpg"/></p><p><img src="/media/goods/images/2_20170719161414_628.jpg" title="" alt="2.jpg"/></p><p><img src="/media/goods/images/2_20170719161435_381.jpg" title="" alt="2.jpg"/></p>' }, { 'images': [ 'goods/images/15_P_1448947257324.jpg', 'goods/images/15_P_1448947257580.jpg' ], 'categorys': [ '首页', '酒水饮料', '洋酒' ], 'market_price': '¥22元', 'name': '茅台53度飞天茅台500ml', 'desc': None, 'sale_price': '¥18元', 'goods_desc':'<p><img src="/media/goods/images/2_20170719161405_249.jpg" title="" alt="2.jpg"/></p><p><img src="/media/goods/images/2_20170719161414_628.jpg" title="" alt="2.jpg"/></p><p><img src="/media/goods/images/2_20170719161435_381.jpg" title="" alt="2.jpg"/></p>' }, { 'images': [ 'goods/images/13_P_1448947460386.jpg', 'goods/images/13_P_1448947460276.jpg', 'goods/images/13_P_1448947460353.jpg' ], 'categorys': [ '首页', '酒水饮料', '葡萄酒' ], 'market_price': '¥42元', 'name': '52度兰陵·紫气东来1600mL山东名酒', 'desc': None, 'sale_price': '¥35元', 'goods_desc':'<p><img src="/media/goods/images/2_20170719161405_249.jpg" title="" alt="2.jpg"/></p><p><img src="/media/goods/images/2_20170719161414_628.jpg" title="" alt="2.jpg"/></p><p><img src="/media/goods/images/2_20170719161435_381.jpg" title="" alt="2.jpg"/></p>' }, { 'images': [ 'goods/images/50_P_1448946543091.jpg', 'goods/images/50_P_1448946542182.jpg' ], 'categorys': [ '首页', '酒水饮料', '饮料/水' ], 'market_price': '¥24元', 'name': 'JohnnieWalker尊尼获加黑牌威士忌', 'desc': None, 'sale_price': '¥20元', 'goods_desc':'<p><img src="/media/goods/images/2_20170719161405_249.jpg" title="" alt="2.jpg"/></p><p><img src="/media/goods/images/2_20170719161414_628.jpg" title="" alt="2.jpg"/></p><p><img src="/media/goods/images/2_20170719161435_381.jpg" title="" alt="2.jpg"/></p>' }, { 'images': [ 'goods/images/51_P_1448946466595.jpg', 'goods/images/51_P_1448946466208.jpg' ], 'categorys': [ '首页', '酒水饮料', '洋酒' ], 'market_price': '¥31元', 'name': '人头马CLUB特优香槟干邑350ml', 'desc': None, 'sale_price': '¥26元', 'goods_desc':'<p><img src="/media/goods/images/2_20170719161405_249.jpg" title="" alt="2.jpg"/></p><p><img src="/media/goods/images/2_20170719161414_628.jpg" title="" alt="2.jpg"/></p><p><img src="/media/goods/images/2_20170719161435_381.jpg" title="" alt="2.jpg"/></p>' }, { 'images': [ 'goods/images/17_P_1448947102246.jpg' ], 'categorys': [ '首页', '酒水饮料', '啤酒' ], 'market_price': '¥54元', 'name': '张裕干红葡萄酒750ml*6支', 'desc': None, 'sale_price': '¥45元', 'goods_desc':'<p><img src="/media/goods/images/2_20170719161405_249.jpg" title="" alt="2.jpg"/></p><p><img src="/media/goods/images/2_20170719161414_628.jpg" title="" alt="2.jpg"/></p><p><img src="/media/goods/images/2_20170719161435_381.jpg" title="" alt="2.jpg"/></p>' }, { 'images': [ 'goods/images/20_P_1448946850602.jpg' ], 'categorys': [ '首页', '酒水饮料', '葡萄酒' ], 'market_price': '¥46元', 'name': '原瓶原装进口洋酒烈酒法国云鹿XO白兰地', 'desc': None, 'sale_price': '¥38元', 'goods_desc':'<p><img src="/media/goods/images/2_20170719161405_249.jpg" title="" alt="2.jpg"/></p><p><img src="/media/goods/images/2_20170719161414_628.jpg" title="" alt="2.jpg"/></p><p><img src="/media/goods/images/2_20170719161435_381.jpg" title="" alt="2.jpg"/></p>' }, { 'images': [ 'goods/images/19_P_1448946951581.jpg', 'goods/images/19_P_1448946951726.jpg' ], 'categorys': [ '首页', '酒水饮料', '白酒' ], 'market_price': '¥82元', 'name': '法国原装进口圣贝克干红葡萄酒750ml', 'desc': None, 'sale_price': '¥68元', 'goods_desc':'<p><img src="/media/goods/images/2_20170719161405_249.jpg" title="" alt="2.jpg"/></p><p><img src="/media/goods/images/2_20170719161414_628.jpg" title="" alt="2.jpg"/></p><p><img src="/media/goods/images/2_20170719161435_381.jpg" title="" alt="2.jpg"/></p>' }, { 'images': [ 'goods/images/18_P_1448947011435.jpg' ], 'categorys': [ '首页', '酒水饮料', '白酒' ], 'market_price': '¥67元', 'name': '法国百利威干红葡萄酒AOP级6支装', 'desc': None, 'sale_price': '¥56元', 'goods_desc':'<p><img src="/media/goods/images/2_20170719161405_249.jpg" title="" alt="2.jpg"/></p><p><img src="/media/goods/images/2_20170719161414_628.jpg" title="" alt="2.jpg"/></p><p><img src="/media/goods/images/2_20170719161435_381.jpg" title="" alt="2.jpg"/></p>' }, { 'images': [ 'goods/images/22_P_1448946729629.jpg' ], 'categorys': [ '首页', '酒水饮料', '洋酒' ], 'market_price': '¥71元', 'name': '芝华士12年苏格兰威士忌700ml', 'desc': None, 'sale_price': '¥59元', 'goods_desc':'<p><img src="/media/goods/images/2_20170719161405_249.jpg" title="" alt="2.jpg"/></p><p><img src="/media/goods/images/2_20170719161414_628.jpg" title="" alt="2.jpg"/></p><p><img src="/media/goods/images/2_20170719161435_381.jpg" title="" alt="2.jpg"/></p>' }, { 'images': [ 'goods/images/45_P_1448946661303.jpg' ], 'categorys': [ '首页', '酒水饮料', '饮料/水' ], 'market_price': '¥31元', 'name': '深蓝伏特加巴维兰利口酒送预调酒', 'desc': None, 'sale_price': '¥18元', 'goods_desc':'<p><img src="/media/goods/images/2_20170719161405_249.jpg" title="" alt="2.jpg"/></p><p><img src="/media/goods/images/2_20170719161414_628.jpg" title="" alt="2.jpg"/></p><p><img src="/media/goods/images/2_20170719161435_381.jpg" title="" alt="2.jpg"/></p>' }, { 'images': [ 'goods/images/32_P_1448948525620.jpg' ], 'categorys': [ '首页', '蔬菜水果', '精选蔬菜' ], 'market_price': '¥43元', 'name': '赣南脐橙特级果10斤装', 'desc': None, 'sale_price': '¥36元', 'goods_desc':'<p><img src="/media/goods/images/2_20170719161405_249.jpg" title="" alt="2.jpg"/></p><p><img src="/media/goods/images/2_20170719161414_628.jpg" title="" alt="2.jpg"/></p><p><img src="/media/goods/images/2_20170719161435_381.jpg" title="" alt="2.jpg"/></p>' }, { 'images': [ 'goods/images/30_P_1448948663450.jpg', 'goods/images/30_P_1448948662571.jpg', 'goods/images/30_P_1448948663221.jpg' ], 'categorys': [ '首页', '蔬菜水果', '进口水果' ], 'market_price': '¥11元', 'name': '泰国菠萝蜜16-18斤1个装', 'desc': '【懒人吃法】菠萝蜜果肉,冰袋保鲜,收货就吃,冰爽Q脆甜,2斤装,全国顺丰空运包邮,发出后48小时内可达,一线城市基本隔天可达', 'sale_price': '¥9元', 'goods_desc':'<p><img src="/media/goods/images/2_20170719161405_249.jpg" title="" alt="2.jpg"/></p><p><img src="/media/goods/images/2_20170719161414_628.jpg" title="" alt="2.jpg"/></p><p><img src="/media/goods/images/2_20170719161435_381.jpg" title="" alt="2.jpg"/></p>' }, { 'images': [ 'goods/images/31_P_1448948598947.jpg', 'goods/images/31_P_1448948598475.jpg' ], 'categorys': [ '首页', '蔬菜水果', '国产水果' ], 'market_price': '¥22元', 'name': '四川双流草莓新鲜水果礼盒2盒', 'desc': None, 'sale_price': '¥18元', 'goods_desc':'<p><img src="/media/goods/images/2_20170719161405_249.jpg" title="" alt="2.jpg"/></p><p><img src="/media/goods/images/2_20170719161414_628.jpg" title="" alt="2.jpg"/></p><p><img src="/media/goods/images/2_20170719161435_381.jpg" title="" alt="2.jpg"/></p>' }, { 'images': [ 'goods/images/35_P_1448948333610.jpg', 'goods/images/35_P_1448948333313.jpg' ], 'categorys': [ '首页', '蔬菜水果', '有机蔬菜' ], 'market_price': '¥67元', 'name': '新鲜头茬非洲冰草冰菜', 'desc': None, 'sale_price': '¥56元', 'goods_desc':'<p><img src="/media/goods/images/2_20170719161405_249.jpg" title="" alt="2.jpg"/></p><p><img src="/media/goods/images/2_20170719161414_628.jpg" title="" alt="2.jpg"/></p><p><img src="/media/goods/images/2_20170719161435_381.jpg" title="" alt="2.jpg"/></p>' }, { 'images': [ 'goods/images/36_P_1448948234405.jpg', 'goods/images/36_P_1448948234250.jpg' ], 'categorys': [ '首页', '蔬菜水果', '有机蔬菜' ], 'market_price': '¥6元', 'name': '仿真蔬菜水果果蔬菜模型', 'desc': None, 'sale_price': '¥5元', 'goods_desc':'<p><img src="/media/goods/images/2_20170719161405_249.jpg" title="" alt="2.jpg"/></p><p><img src="/media/goods/images/2_20170719161414_628.jpg" title="" alt="2.jpg"/></p><p><img src="/media/goods/images/2_20170719161435_381.jpg" title="" alt="2.jpg"/></p>' }, { 'images': [ 'goods/images/33_P_1448948479966.jpg', 'goods/images/33_P_1448948479886.jpg' ], 'categorys': [ '首页', '蔬菜水果', '精选蔬菜' ], 'market_price': '¥28元', 'name': '现摘芭乐番石榴台湾珍珠芭乐', 'desc': '''海南产精品释迦果, 释迦是水果中的贵族, 产量少, 味道很甜, 奶香十足, 非常可口, 果裹果园顺丰空运, 保证新鲜.果子个大, 一斤1-2个左右, 大个头的果子更尽兴! ''', 'sale_price': '¥23元', 'goods_desc':'<p><img src="/media/goods/images/2_20170719161405_249.jpg" title="" alt="2.jpg"/></p><p><img src="/media/goods/images/2_20170719161414_628.jpg" title="" alt="2.jpg"/></p><p><img src="/media/goods/images/2_20170719161435_381.jpg" title="" alt="2.jpg"/></p>' }, { 'images': [ 'goods/images/34_P_1448948399009.jpg' ], 'categorys': [ '首页', '蔬菜水果', '国产水果' ], 'market_price': '¥46元', 'name': '潍坊萝卜5斤/箱礼盒', 'desc': '脐橙规格是65-90MM左右(标准果果径平均70MM左右,精品果果径平均80MM左右),一斤大概有2-4个左右,脐橙产自江西省赣州市信丰县安西镇,全过程都是采用农家有机肥种植,生态天然', 'sale_price': '¥38元', 'goods_desc':'<p><img src="/media/goods/images/2_20170719161405_249.jpg" title="" alt="2.jpg"/></p><p><img src="/media/goods/images/2_20170719161414_628.jpg" title="" alt="2.jpg"/></p><p><img src="/media/goods/images/2_20170719161435_381.jpg" title="" alt="2.jpg"/></p>' }, { 'images': [ 'goods/images/43_P_1448948762645.jpg' ], 'categorys': [ '首页', '休闲食品' ], 'market_price': '¥154元', 'name': '休闲零食膨化食品焦糖/奶油/椒麻味', 'desc': None, 'sale_price': '¥99元', 'goods_desc':'<p><img src="/media/goods/images/2_20170719161405_249.jpg" title="" alt="2.jpg"/></p><p><img src="/media/goods/images/2_20170719161414_628.jpg" title="" alt="2.jpg"/></p><p><img src="/media/goods/images/2_20170719161435_381.jpg" title="" alt="2.jpg"/></p>' }, { 'images': [ 'goods/images/38_P_1448949220255.jpg' ], 'categorys': [ '首页', '奶类食品', '奶粉' ], 'market_price': '¥84元', 'name': '蒙牛未来星儿童成长牛奶骨力型190ml*15盒', 'desc': None, 'sale_price': '¥70元', 'goods_desc':'<p><img src="/media/goods/images/2_20170719161405_249.jpg" title="" alt="2.jpg"/></p><p><img src="/media/goods/images/2_20170719161414_628.jpg" title="" alt="2.jpg"/></p><p><img src="/media/goods/images/2_20170719161435_381.jpg" title="" alt="2.jpg"/></p>' }, { 'images': [ 'goods/images/44_P_1448948850187.jpg' ], 'categorys': [ '首页', '奶类食品', '进口奶品' ], 'market_price': '¥70元', 'name': '蒙牛特仑苏有机奶250ml×12盒', 'desc': None, 'sale_price': '¥32元', 'goods_desc':'<p><img src="/media/goods/images/2_20170719161405_249.jpg" title="" alt="2.jpg"/></p><p><img src="/media/goods/images/2_20170719161414_628.jpg" title="" alt="2.jpg"/></p><p><img src="/media/goods/images/2_20170719161435_381.jpg" title="" alt="2.jpg"/></p>' }, { 'images': [ 'images/201511/goods_img/49_P_1448162819889.jpg' ], 'categorys': [ '首页', '奶类食品' ], 'market_price': '¥1元', 'name': '1元支付测试商品', 'desc': None, 'sale_price': '¥1元', 'goods_desc':'<p><img src="/media/goods/images/2_20170719161405_249.jpg" title="" alt="2.jpg"/></p><p><img src="/media/goods/images/2_20170719161414_628.jpg" title="" alt="2.jpg"/></p><p><img src="/media/goods/images/2_20170719161435_381.jpg" title="" alt="2.jpg"/></p>' }, { 'images': [ 'goods/images/40_P_1448949038702.jpg' ], 'categorys': [ '首页', '奶类食品', '进口奶品' ], 'market_price': '¥70元', 'name': '德运全脂新鲜纯牛奶1L*10盒装整箱', 'desc': None, 'sale_price': '¥58元', 'goods_desc':'<p><img src="/media/goods/images/2_20170719161405_249.jpg" title="" alt="2.jpg"/></p><p><img src="/media/goods/images/2_20170719161414_628.jpg" title="" alt="2.jpg"/></p><p><img src="/media/goods/images/2_20170719161435_381.jpg" title="" alt="2.jpg"/></p>' }, { 'images': [ 'goods/images/39_P_1448949115481.jpg' ], 'categorys': [ '首页', '奶类食品', '有机奶' ], 'market_price': '¥38元', 'name': '木糖醇红枣早餐奶即食豆奶粉538g', 'desc': None, 'sale_price': '¥32元', 'goods_desc':'<p><img src="/media/goods/images/2_20170719161405_249.jpg" title="" alt="2.jpg"/></p><p><img src="/media/goods/images/2_20170719161414_628.jpg" title="" alt="2.jpg"/></p><p><img src="/media/goods/images/2_20170719161435_381.jpg" title="" alt="2.jpg"/></p>' }, { 'images': [ 'goods/images/41_P_1448948980358.jpg' ], 'categorys': [ '首页', '奶类食品', '原料奶' ], 'market_price': '¥26元', 'name': '高钙液体奶200ml*24盒', 'desc': None, 'sale_price': '¥22元', 'goods_desc':'<p><img src="/media/goods/images/2_20170719161405_249.jpg" title="" alt="2.jpg"/></p><p><img src="/media/goods/images/2_20170719161414_628.jpg" title="" alt="2.jpg"/></p><p><img src="/media/goods/images/2_20170719161435_381.jpg" title="" alt="2.jpg"/></p>' }, { 'images': [ 'goods/images/37_P_1448949284365.jpg' ], 'categorys': [ '首页', '奶类食品', '国产奶品' ], 'market_price': '¥720元', 'name': '新西兰进口全脂奶粉900g', 'desc': None, 'sale_price': '¥600元', 'goods_desc':'<p><img src="/media/goods/images/2_20170719161405_249.jpg" title="" alt="2.jpg"/></p><p><img src="/media/goods/images/2_20170719161414_628.jpg" title="" alt="2.jpg"/></p><p><img src="/media/goods/images/2_20170719161435_381.jpg" title="" alt="2.jpg"/></p>' }, { 'images': [ 'goods/images/42_P_1448948895193.jpg' ], 'categorys': [ '首页', '奶类食品', '进口奶品' ], 'market_price': '¥43元', 'name': '伊利官方直营全脂营养舒化奶250ml*12盒*2提', 'desc': None, 'sale_price': '¥36元', 'goods_desc':'<p><img src="/media/goods/images/2_20170719161405_249.jpg" title="" alt="2.jpg"/></p><p><img src="/media/goods/images/2_20170719161414_628.jpg" title="" alt="2.jpg"/></p><p><img src="/media/goods/images/2_20170719161435_381.jpg" title="" alt="2.jpg"/></p>' }, { 'sale_price': '¥156元', 'images': [ 'goods/images/27_P_1448947771805.jpg' ], 'market_price': '¥187元', 'categorys': [ '首页', '粮油副食', '厨房调料' ], 'desc': None, 'name': '维纳斯橄榄菜籽油5L/桶', 'goods_desc':'<p><img src="/media/goods/images/2_20170719161405_249.jpg" title="" alt="2.jpg"/></p><p><img src="/media/goods/images/2_20170719161414_628.jpg" title="" alt="2.jpg"/></p><p><img src="/media/goods/images/2_20170719161435_381.jpg" title="" alt="2.jpg"/></p>' }, { 'sale_price': '¥15元', 'images': [ 'goods/images/23_P_1448948070348.jpg' ], 'market_price': '¥18元', 'categorys': [ '首页', '粮油副食', '食用油' ], 'desc': None, 'name': '糙米450gx3包粮油米面', 'goods_desc':'<p><img src="/media/goods/images/2_20170719161405_249.jpg" title="" alt="2.jpg"/></p><p><img src="/media/goods/images/2_20170719161414_628.jpg" title="" alt="2.jpg"/></p><p><img src="/media/goods/images/2_20170719161435_381.jpg" title="" alt="2.jpg"/></p>' }, { 'sale_price': '¥45元', 'images': [ 'goods/images/26_P_1448947825754.jpg' ], 'market_price': '¥54元', 'categorys': [ '首页', '粮油副食', '调味品' ], 'desc': None, 'name': '精炼一级大豆油5L色拉油粮油食用油', 'goods_desc':'<p><img src="/media/goods/images/2_20170719161405_249.jpg" title="" alt="2.jpg"/></p><p><img src="/media/goods/images/2_20170719161414_628.jpg" title="" alt="2.jpg"/></p><p><img src="/media/goods/images/2_20170719161435_381.jpg" title="" alt="2.jpg"/></p>' }, { 'sale_price': '¥26元', 'images': [ 'goods/images/28_P_1448947699948.jpg', 'goods/images/28_P_1448947699777.jpg' ], 'market_price': '¥31元', 'categorys': [ '首页', '粮油副食', '南北干货' ], 'desc': None, 'name': '橄榄玉米油5L*2桶', 'goods_desc':'<p><img src="/media/goods/images/2_20170719161405_249.jpg" title="" alt="2.jpg"/></p><p><img src="/media/goods/images/2_20170719161414_628.jpg" title="" alt="2.jpg"/></p><p><img src="/media/goods/images/2_20170719161435_381.jpg" title="" alt="2.jpg"/></p>' }, { 'sale_price': '¥9元', 'images': [ 'goods/images/24_P_1448948023823.jpg', 'goods/images/24_P_1448948023977.jpg' ], 'market_price': '¥11元', 'categorys': [ '首页', '粮油副食', '方便速食' ], 'desc': None, 'name': '山西黑米农家黑米4斤', 'goods_desc':'<p><img src="/media/goods/images/2_20170719161405_249.jpg" title="" alt="2.jpg"/></p><p><img src="/media/goods/images/2_20170719161414_628.jpg" title="" alt="2.jpg"/></p><p><img src="/media/goods/images/2_20170719161435_381.jpg" title="" alt="2.jpg"/></p>' }, { 'sale_price': '¥12元', 'images': [ 'goods/images/25_P_1448947875346.jpg' ], 'market_price': '¥14元', 'categorys': [ '首页', '粮油副食', '米面杂粮' ], 'desc': None, 'name': '稻园牌稻米油粮油米糠油绿色植物油', 'goods_desc':'<p><img src="/media/goods/images/2_20170719161405_249.jpg" title="" alt="2.jpg"/></p><p><img src="/media/goods/images/2_20170719161414_628.jpg" title="" alt="2.jpg"/></p><p><img src="/media/goods/images/2_20170719161435_381.jpg" title="" alt="2.jpg"/></p>' }, { 'sale_price': '¥12元', 'images': [ 'goods/images/29_P_1448947631994.jpg' ], 'market_price': '¥14元', 'categorys': [ '首页', '粮油副食', '食用油' ], 'desc': None, 'name': '融氏纯玉米胚芽油5l桶', 'goods_desc':'<p><img src="/media/goods/images/2_20170719161405_249.jpg" title="" alt="2.jpg"/></p><p><img src="/media/goods/images/2_20170719161414_628.jpg" title="" alt="2.jpg"/></p><p><img src="/media/goods/images/2_20170719161435_381.jpg" title="" alt="2.jpg"/></p>' } ] pass
# -*- coding: utf-8 -*- __author__ = 'bobby' #独立使用django的model import sys import os pwd = os.path.dirname(os.path.realpath(__file__)) sys.path.append(pwd+"../") os.environ.setdefault("DJANGO_SETTINGS_MODULE", "MxShop.settings") import django django.setup() from goods.models import GoodsCategory from db_tools.data.category_data import row_data for lev1_cat in row_data: lev1_intance = GoodsCategory() lev1_intance.code = lev1_cat["code"] lev1_intance.name = lev1_cat["name"] lev1_intance.category_type = 1 lev1_intance.save() for lev2_cat in lev1_cat["sub_categorys"]: lev2_intance = GoodsCategory() lev2_intance.code = lev2_cat["code"] lev2_intance.name = lev2_cat["name"] lev2_intance.category_type = 2 lev2_intance.parent_category = lev1_intance lev2_intance.save() for lev3_cat in lev2_cat["sub_categorys"]: lev3_intance = GoodsCategory() lev3_intance.code = lev3_cat["code"] lev3_intance.name = lev3_cat["name"] lev3_intance.category_type = 3 lev3_intance.parent_category = lev2_intance lev3_intance.save()
# -*- coding: utf-8 -*- __author__ = 'bobby' import sys import os pwd = os.path.dirname(os.path.realpath(__file__)) sys.path.append(pwd+"../") os.environ.setdefault("DJANGO_SETTINGS_MODULE", "MxShop.settings") import django django.setup() from goods.models import Goods, GoodsCategory, GoodsImage from db_tools.data.product_data import row_data for goods_detail in row_data: goods = Goods() goods.name = goods_detail["name"] goods.market_price = float(int(goods_detail["market_price"].replace("¥", "").replace("元", ""))) goods.shop_price = float(int(goods_detail["sale_price"].replace("¥", "").replace("元", ""))) goods.goods_brief = goods_detail["desc"] if goods_detail["desc"] is not None else "" goods.goods_desc = goods_detail["goods_desc"] if goods_detail["goods_desc"] is not None else "" goods.goods_front_image = goods_detail["images"][0] if goods_detail["images"] else "" category_name = goods_detail["categorys"][-1] category = GoodsCategory.objects.filter(name=category_name) if category: goods.category = category[0] goods.save() for goods_image in goods_detail["images"]: goods_image_instance = GoodsImage() goods_image_instance.image = goods_image goods_image_instance.goods = goods goods_image_instance.save()
运行db_too/db_tool/import_category_data.py 和db_too/db_tool/import_goods_data.py
创建管路员用户,登陆后台我们可以看到