def consigner_send_good(): res = { "state": "success", "msg": "change applicaton-state successfully", "data": [] } request_data = request.get_json() good_name = request_data.get("good_name") good_type = request_data.get("good_type") transport_origin = request_data.get("transport_origin") transport_des = request_data.get("transport_des") transport_money = request_data.get("transport_money") transport_time = request_data.get("transport_time") backup = request_data.get("backup") try: good = Good(good_name=good_name, goodtype_id=good_type, transport_origin=transport_origin, transport_des=transport_des, transport_money=transport_money, transport_time=transport_time, backup=backup) good.consigner_id = session.get("id") db.session.add(good) db.session.commit() except Exception as e: res["msg"] = str(e) return jsonify(res)
def create(good_name, good_price, good_weight, good_number, category_id, photos, good_desc, attributes, hot_number, good_state, is_promote): if Good.query.filter(or_(Good.good_name == good_name)).first(): return ValidationErrorResult(message='Good已存在') good = Good(good_name=good_name, good_state=good_state, good_price=good_price, good_number=good_number, good_weight=good_weight, good_desc=good_desc, hot_number=hot_number, is_promote=is_promote) category = Category.query.filter(Category.id == category_id).one() if category: category.goods.append(good) good.category_id = category_id if photos: for photo in photos: ph = Photo(photo_name=photo['photo_name'], photo_url=photo['photo_url']) good.photos.append(ph) if attributes: for attribute in attributes: attr = Attribute.query.filter( Attribute.id == attribute['id']).one() if attr: attr.attribute_values = attribute['attribute_values'] db.session.add(good) db.session.flush() return jsonify(schemas.good_schema.dump(good)), 201
def goods_post(): name = request.args.get('name') category = request.args.get('category') num = request.args.get('num') last_time = request.args.get('last_time') stu_num = request.args.get('stu_num') s_academy = request.args.get('academy') if not (name and category and num and stu_num and s_academy and last_time): return error('提交参数不合法') academy = None if get_stu_academy(stu_num) and len(stu_num) == 8: academy = get_stu_academy(stu_num) else: return error('学号不符合规范') if academy != s_academy: return error('学号与学院不符合') userid = session['base_info']['userid'] user = User.query.filter_by(id=userid).first() good = Good(academy, name, category, num, last_time, user) good.save() return success('提交申请成功')
def forge1(goods=20): click.echo(f"生成{goods}条good数据:") f = Faker("zh_CN") good_types = ["果疏", "金属", "电子器件"] good_prices = [1000, 1300, 1400] for i in range(len(good_types)): goodtype = GoodType(type_name=good_types[i], good_price=good_prices[i]) db.session.add(goodtype) db.session.commit() goodtypes = GoodType.query.all() consigners = Consigner.query.all() for _ in range(int(goods)): good = Good(good_name=f.name(), goodtype_id=goodtypes[randint(0, len(goodtypes) - 1)].id, transport_origin=f.address(), transport_des=f.address(), transport_money=f.numerify(), backup=f.text(), consigner_id=consigners[randint(0, len(consigners) - 1)].id) db.session.add(good) db.session.commit() click.echo("Done...")
def goods(request, pid): username = request.session.get('username') # pone = Post.objects.filter(id=pid)[0] # 方法2主键用get可以直接获取单个对象 pone = Post.objects.get(id=pid) user = User.objects.filter(username=username)[0] if Good.objects.filter(post=pone, user=user).count() < 1: goods = Good.create(post=pone, user=user) goods.save() return redirect('/postdetail/{}/'.format(pid))
def add_good(request): assert isinstance(request, HttpRequest) result = str(request.POST) if request.POST.get('images') != None: new_item = request.POST.get('new_good').split('&') Good(name=decoder(new_item[0].split("=")[1]), description=decoder(new_item[1].split("=")[1]), price=float(new_item[2].split("=")[1]), other_images=decoder(request.POST.get('images'))).save() else: data = {} data['result'] = 'Success' return HttpResponse(json.dumps(data), content_type="application/json") return JsonResponse({})
def addNewGood(name, parent, intro, icon): # 检测不能添加同名商品 good = Category.query.filter_by(name=name).first() if good != None: return False # 在类别表中新建商品记录 newCat = Category(name=name, parent=parent, level=4) db.session.add(newCat) db.session.commit() # 在商品表中新建商品记录 newGood = Good(id=newCat.id, intro=intro, icon=icon) db.session.add(newGood) db.session.commit() return True
def addgood(request): goods = Good() goods.name = '运动鞋%d' % random.randrange(5) goods.brand = '耐克' goods.save() custom = Custom() custom.name = '张三%d' % random.randrange(5) custom.sex = '男' custom.save() #注意要在保存后添加 而且要用外键.add(主表对象) custom.good.add(goods) return HttpResponse('添加成功')
categorys = Category.query.all() for category in categorys: db.session.delete(category) db.session.commit() db.create_all() delete_db() title = 'good' price = 1 quantity = 1 category = Category(category='куб') for i in range(100): good = Good(title=title, price=price, quantity=quantity, category=category, desc=title) db.session.add(good) title = 'good' price += 1 quantity += 1 title = title + str(price) db.session.commit()