def addGoods(request): goods=Goods() goods.name=request.GET['name'] goods.description=request.GET['description'] goods.picture1=open("tmp\\nokia1.jpg","rb") goods.picture2=open("tmp\\nokia2.jpg","rb") goods.picture3=open("tmp\\nokia3.jpg","rb") goods.price=105 # goods.time=datetime.datetime.now goods.save() return HttpResponse("success")
def __init__(self): super(GoodsCreater, self).__init__(0) counter = 300 while counter != 0: new_object = Goods() new_object.supplier = self.rdm_choice(self.LIST_OF_SUPPLIERS) new_object.name = self.rdm_choice(self.LIST_OF_GOODS_NAMES) new_object.price = randrange(0, 100) path = self.user_goods_directory_path( new_object, self.rdm_choice(self.LIST_OF_PICTURES)) print(path) new_object.picture = path new_object.description = self.rdm_choice(self.LIST_OF_DESCRIPTION) new_object.save() print(new_object) counter -= 1
sys.path.append(pwd + "../") os.environ.setdefault("DJANGO_SETTINGS_MODULE", "daydah_store2.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.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()