Beispiel #1
0
def delete_children(id_):
    children = Goods.select().where(Goods.parent_id == id_)
    if (len(children) != 0):
        for child in children:
            delete(child.id)
    query = Goods.delete().where(Goods.id == id_)
    query.execute()
Beispiel #2
0
def add_goods(request):
    if request.method == 'GET':
        return render_to_response('add_goods.html', {
            'request': request,
            'title': '添加商品',
            'header': '添加商品'
        })
    elif request.method == 'POST':
        user = request.user
        goodsname = request.POST['goodsname']
        price = request.POST['price']
        goodstype = request.POST['goodstype']
        goods = Goods(name=goodsname,
                      price=price,
                      goods_type=goodstype,
                      add_people=user)
        goods.save()
        shops = Shop.objects.all()
        for shop in shops:
            goodsshop = GoodsShop(goods=goods,
                                  shop=shop,
                                  remain=0,
                                  last_updater=user)
            goodsshop.save()
        return HttpResponseRedirect(reverse('addsuccess'))
Beispiel #3
0
def change(id_, amount_):
    item = Goods.select().where(Goods.id == id_)[0]
    query = Goods.update({Goods.amount: amount_}).where(Goods.id == id_)
    query.execute()
    amount = amount_ - item.amount
    if (amount_ != 0):
        update_amount(item.parent_id, amount)
    return item
Beispiel #4
0
def update_amount(id_, amount_):
    item = Goods.select().where(Goods.id == id_)[0]
    query = Goods.update({
        Goods.amount: Goods.amount + amount_
    }).where(Goods.id == id_)
    query.execute()
    if (item.parent_id != None):
        update_amount(item.parent_id, amount_)
Beispiel #5
0
 def put(id_key=None):
     data = ShopSchema().loads(json.dumps(request.json))
     print(data)
     try:
         Goods.objects(id=id_key).update(**data)
     except ValidationError as e:
         return e.messages
     return data
Beispiel #6
0
def clear_base():
    query = Goods.delete().where(Goods.id != 1)
    query.execute()
    query = Goods.update({Goods.amount: 0}).where(Goods.id == 0)
    query.execute()
    query = Orders_Info.delete().where(Orders_Info.id > 0)
    query.execute()
    query = Orders_Content.delete().where(Orders_Content.id > 0)
    query.execute()
Beispiel #7
0
def update_model():
    good = Goods.get_by_id(2)
    #更新
    # good.click_num += 1
    # good.save()
    # Goods.update(click_num=Goods.click_num + 1).where(Goods.id == 1).execute()

    #删除
    # good.delete_instance()
    Goods.delete().where(Goods.id==2).execute()
Beispiel #8
0
def db_add(request):
    goods = Goods(name="pumeloes")
    goods.price = '12.3'
    goods.barcode = '123456789'
    goods.package = 'box'
    goods.level = 'one'
    goods.origin = 'china'
    goods.unit = '500g'
    goods.save()
    return HttpResponse("success")
Beispiel #9
0
def delete(id_):
    children = Goods.select().where(Goods.parent_id == id_)
    if (len(children) != 0):
        for child in children:
            delete_children(child.id)

    if (id_ != 1):
        amount = Goods.select().where(Goods.id == id_)[0].amount
        update_amount(id_, -amount)
        query = Goods.delete().where(Goods.id == id_)
        query.execute()
Beispiel #10
0
 def save_good(self):
     for name in name2cids.keys():
         for goods in self.get_goods_by_type(name2cids.get(name)):
             for good in goods:
                 try:
                     if not Goods.get_or_none(Goods.cid == good.cid):
                         Goods.create(**good.to_json())
                 except PeeweeException as e:
                     print(e)
                     pass
         self.jd.set_new_env()
         print('{}类保存完毕'.format(name))
Beispiel #11
0
def save_model():
    for supplier in supplier_list:
        supplier_obj = Supplier()
        supplier_obj.name = supplier["name"]
        supplier_obj.address = supplier["address"]
        supplier_obj.phone = supplier["phone"]
        supplier_obj.save()

    for record in goods_list:
        good = Goods(**record)
        good.save()

    pass
Beispiel #12
0
def add_goods(request):
    if request.method == 'GET':
        return render_to_response('add_goods.html', {'request': request, 'title': '添加商品', 'header': '添加商品'})
    elif request.method == 'POST':
        user = request.user
        goodsname = request.POST['goodsname']
        price = request.POST['price']
        goodstype = request.POST['goodstype']
        goods = Goods(name=goodsname, price=price, goods_type=goodstype, add_people=user)
        goods.save()
        shops = Shop.objects.all()
        for shop in shops:
            goodsshop = GoodsShop(goods=goods, shop=shop, remain=0, last_updater=user)
            goodsshop.save()
        return HttpResponseRedirect(reverse('addsuccess'))
Beispiel #13
0
async def handler():
    # await objects.create(Goods, supplier_id=2, name="53度水井坊臻酿八號500ml", click_num=20, goods_num=1000, price=500,
    #                      brief="州茅台酒厂(集团)保健酒业有限公司生产")

    goods = await objects.execute(Goods.select())
    for good in goods:
        print(good.name, good.price)
Beispiel #14
0
def add(name_, amount_, parent_id_, price_):
    item = Goods.create(name=name_,
                        amount=amount_,
                        price=price_,
                        parent_id=parent_id_)
    if (amount_ != 0):
        update_amount(item.parent_id, amount_)
    return item.id
Beispiel #15
0
def get_full_name_by_id(id_):
    if id_ == 1:
        return ''
    item = Goods.select().where(Goods.id == id_)
    if (item[0].parent_id.id != 1):
        res = '{}::{}'.format(get_full_name_by_id(item[0].parent_id),
                              item[0].name)
    else:
        res = item[0].name
    return res
Beispiel #16
0
 def get(id_key=None):
     if id_key:
         try:
             for product in Goods.objects(id=id_key):
                 print(
                     f'product.id:{product.id}, product.name:{product.name}'
                 )
                 Goods.objects(id=id_key).update_one(inc__views=1)
                 return ShopSchema().dumps(product)
         except ValidationError as e:
             return e.messages
     else:
         for product in Goods.objects():
             category_obj = product['category']
             print(category_obj.id, category_obj.cat_name,
                   category_obj.description)
             print(
                 f'product.id:{product.id}, product.price:{product.price}, product.views:{product.views}'
             )
         return ShopSchema(many=True).dumps(Goods.objects().all())
Beispiel #17
0
def buy_item(id_, amount_, order_id):
    item = Goods.select().where(Goods.id == id_)[0]
    if (item.amount < amount_):
        raise OverflowError(' '.join([
            'Этого товара осталось всего',
            str(item.amount), '\nВведите другое количество'
        ]))
    if (amount_ <= 0):
        raise OverflowError('\n'.join([
            'Число товаров должно быть натуральным',
            'Введите другое количество'
        ]))

    price = Goods.select().where(Goods.id == id_)[0].price
    same_item = Orders_Content.select().where((
        Orders_Content.order_id == order_id) & (Orders_Content.item_id == id_))
    if same_item.exists():
        query = Orders_Content.update({
            Orders_Content.amount:
            Orders_Content.amount + amount_,
            Orders_Content.cost:
            Orders_Content.cost + amount_ * price
        }).where((Orders_Content.order_id == order_id)
                 & (Orders_Content.item_id == id_))
        query.execute()
    else:
        Orders_Content.create(order_id=order_id,
                              item_id=id_,
                              amount=amount_,
                              cost=price * amount_)

    query = Orders_Info.update({
        Orders_Info.time: time.time()
    }).where(Orders_Info.id == order_id)
    query.execute()

    update_amount(id_, -amount_)
    def addGoods(self):
        # image = self.image
        image_filename = 'user' + self.image.filename
        image_path = 'http://' + ip_address + 'img/' + image_filename

        newGood = Goods(
            category=self.formDict.get('category'),
            name=self.formDict.get('name'),
            word_description=self.formDict.get('word_description'),
            image=image_path,
            price=self.formDict.get('price'),
            remaining=self.formDict.get('remaining')
        )
        db.session.add(newGood)
        db.session.commit()
        # 提交后没问题再进行保存图片
        self.image.save('./static/img/' + image_filename)
        result = {'code':200}
        return jsonify(result)
Beispiel #19
0
def Add():
    form = GoodsForm()
    if request.method == 'POST':
        writer_id = form.writer_id.data
        # token = form.token.data
        temp = WxUser.query.filter_by(id=writer_id).first()  #
        rdSession = form.rdSession.data  #
        # if certify_token(writer_id, token):
        if certify_rdSession(temp.openid, temp.session_key, rdSession):  #
            name = form.name.data
            price = form.price.data
            content = form.content.data
            phone = form.phone.data
            wechat = form.wechat.data
            email = form.email.data
            type = form.type.data
            createTime = local_time()
            state = 1
            commentNum = 0
            image = form.images.data
            img_url = upload_image(image)
            if name and price and content and type:
                try:
                    new_goods = Goods(name=name, createTime=createTime, state=state, price=price, content=content,
                                      image=img_url, phone=phone, wechat=wechat, email=email, commentNum=commentNum,
                                      writer_id=writer_id, type=type)

                    db.session.add(new_goods)
                    db.session.commit()
                    return '上传成功'
                except Exception as e:
                    print(e)
                    flash('添加商品失败')
                    db.session.rollback()
                    return '添加失败'
            else:
                return '参数出错'
        else:
            return '登录超时'

    return render_template('upload.html', form=form)
Beispiel #20
0
def goods_insert():
    """Goods Insert"""

    products = (
        ('제품1', 30000, 'wenyang-x700.jpg', 10, 3, '제품1에 대한 설명이 여기에 들어옵니다'),
        ('제품2', 33000, 'tamara-bellis-x700.jpg', 10, 5, '제품2에 대한 설명이 여기에 들어옵니다'),
        ('제품3', 35000, 'roland-denes-x700.jpg', 10, 1, '제품3에 대한 설명이 여기에 들어옵니다'),
        ('제품4', 33000, 'raamin-ka-x700.jpg', 10, 2, '제품4에 대한 설명이 여기에 들어옵니다'),
        ('제품5', 31000, 'oliver-johnson-x700.jpg', 10, 5, '제품5에 대한 설명이 여기에 들어옵니다'),
        ('제품6', 36000, 'taisiia-stupak-x700.jpg', 10, 4, '제품6에 대한 설명이 여기에 들어옵니다')
    )

    for item in products:
        goods = Goods()
        goods.goods_name = item[0]
        goods.price = item[1]
        goods.goods_photo = item[2]
        goods.goods_cnt = item[3]
        goods.goods_ranking = item[4]
        goods.goods_description = item[5]

        db_session.add(goods)
    
    db_session.commit()
Beispiel #21
0
 def get_goods_by_type(self, type):
     url = self.goods_list_url.format(cids=type, page=1)
     for page in range(1, self.get_max_page(url) + 1):
         html = self.get(self.goods_list_url.format(cids=type, page=page))
         html.encoding = 'utf-8'
         html = html.text
         soup = BeautifulSoup(html, parser)
         items = soup.find_all('li', class_='item')
         goods = []
         for i in items:
             count = int(re.search(r'提供([0-9]*)份', i.text).group(1))
             cid = int(i.attrs['activity_id'])
             endt = int(i.attrs['end_time'])
             skuid = i.attrs['sku_id']
             name = i.find('div', class_='p-name').text
             good = Goods(cid=cid,
                          name=name,
                          count=count,
                          endt=endt,
                          skuid=skuid)
             goods.append(good)
         self.get_money_by_skuids(goods)
         yield goods
         time.sleep(0.3)
Beispiel #22
0
def query_model():
    # 获取某一条数据
    # good = Goods.get(Goods.id == 1)
    # good = Goods.get_by_id(1)
    # good = Goods[1]

    # select 返回的是modelselect对象
    # 获取所有数据
    # select price from goods
    goods = Goods.select()

    # select * from goods where price > 100
    goods = Goods.select().where(Goods.price > 100)

    # select * from goods where price>100 and click_num>200
    goods = Goods.select().where((Goods.price > 100) & (Goods.click_num > 200))

    # select * from goods where name like "%飞天"
    goods = Goods.select().where(Goods.name.contains("飞天"))

    # select * from goods where id in (1, 3)
    # goods = Goods.select().where(Goods.id<<[1, 3])
    # goods = Goods.select().where((Goods.id == 1) | (Goods.id == 3))
    goods = Goods.select().where(Goods.id.in_([1, 3]))

    # select * from goods where price>click_num
    goods = Goods.select().where(Goods.price > Goods.click_num)

    # 排序 select * from goods order by price desc
    # goods = Goods.select().order_by(Goods.price)
    goods = Goods.select().order_by(-Goods.price)

    # 分页
    # goods = Goods.select().order_by(Goods.price).paginate(1, 2)

    for good in goods:
        print(good.name, good.price)
    pass
Beispiel #23
0
def get_prev_level(id_):
    item = Goods.select().where(Goods.id == id_)
    return item[0].parent_id.id
Beispiel #24
0
    def regSupplierCotrl(self, request):
        try:
            supplier_name = request.form['supplier_name']
            supplier_companyname = request.form['supplier_companyname']
            supplier_cin = request.form['supplier_cin']
            supplier_address = request.form['supplier_address']
            supplier_country = request.form.get('country')
            country = supplier_country.split("_")[0]
            isd = supplier_country.split("_")[1]
            #print supplier_country
            supplier_state = request.form.get('state')
            supplier_city = request.form.get('city')
            supplier_town = request.form['supplier_town']
            supplier_pin = request.form['supplier_pin']
            supplier_phone = request.form['supplier_phone']
            supplier_mail = request.form['supplier_mail']
            supplier_gstin = request.form['supplier_gstin']
            supplier_pan = request.form['supplier_pan']
            supplier_brand = request.form.getlist('brand')
            supplier_tm = request.form.getlist('supplier_tm')
            supplier_contactname = request.form['supplier_contactname']
            supplier_mobile = request.form['supplier_mobile']
            supplier_email = request.form['supplier_email']
            #iscompanyExist=Reg_Supplier.objects(supplier_companyname=supplier_companyname)
            #iscinExist=Reg_Supplier.objects(supplier_cin=supplier_cin)
            #isgstinExist=Reg_Supplier.objects(supplier_gstin=supplier_gstin)
            #ispanExist=Reg_Supplier.objects(supplier_pan=supplier_pan)
            '''if iscompanyExist.count()>0:
                return  'Fail'
            elif iscinExist.count()>0:
                 return  'Fail'
            elif isgstinExist.count()>0:
                 return  'Fail'
            elif ispanExist.count()>0:
                 return  'Fail'''
            #return isd
            supplierUser = Reg_Supplier(
                user_id=str(current_user.id),
                supplier_name=supplier_name,
                supplier_companyname=supplier_companyname,
                supplier_cin=supplier_cin,
                supplier_address=supplier_address,
                supplier_country=country,
                supplier_state=supplier_state,
                supplier_city=supplier_city,
                supplier_town=supplier_town,
                supplier_pin=supplier_pin,
                supplier_isd=isd,
                supplier_phone=supplier_phone,
                supplier_mail=supplier_mail.lower(),
                supplier_gstin=supplier_gstin,
                supplier_pan=supplier_pan,
                supplier_contactname=supplier_contactname,
                supplier_mobile=supplier_mobile,
                supplier_email=supplier_email.lower(),
                supplier_id='0')  # Insert form data in collection

            supplierUser.save()
            for x in range(len(supplier_brand)):
                goods = Goods(supplier_brand[x], supplier_tm[x])
                supplierUser.supplier_brands.append(goods)
                supplierUser.save()

            user = UserSignup.objects.get(id=current_user.id)
            user.status = 'Review'
            user.save()
            return str("Success")
        except Exception as e:
            return str("Fail")
Beispiel #25
0
def savegoods(request):
    params = request.POST;
    community = Community.objects.get(number=params["communityId"])
    group = UserGroupProfile.objects.filter(user=request.user,community=community)[0]
    goods = Goods()
    goods.name = params["name"]
    img = re.compile(r'^/media').sub("/image",params["image"])
    fimg = re.compile(r'^/media').sub("",params["image"])
    goods.image = img
    goods.groupProfile = group
    goods.link = params["link"]
    goods.price = float(params["price"])
    goods.offprice = float(params["sale"])
    goods.desc = params['desc']
    goods.community = community
    goods.save()
    indexs = params.getlist("categoryIndex")
    for index in indexs:
        category = Category()
        category.name = params["categoryName"+index]
        category.save()
        cvs = params.getlist("categoryValue"+index+"[]")
        for cvp in cvs:
            cv = CategoryValue()
            cv.category = category
            cv.value = cvp
            cv.save()
        gc = GoodsCategory()
        gc.category = category
        gc.product = goods
        gc.save()
    if re.search('^http://',params["image"]) == None:
        try:
            os.mkdir("/www/image/"+str(request.user.id))
        except:
            pass
        shutil.move("/www/tmp/"+fimg,"/www/image/"+str(request.user.id))
    return HttpResponseRedirect(redirect_to=reverse("mm:index"))
Beispiel #26
0
def delete_overtime():
    now = int(time.time() * 1000)
    goods = Goods.select().filter(Goods.endt < now)
    [good.delete_instance() for good in goods]
    print("删除{}个过期物品".format(len(goods)))
Beispiel #27
0
    # 分页
    # goods = Goods.select().order_by(Goods.price).paginate(1, 2)

    for good in goods:
        print(good.name, good.price)
    pass


def update_model():
    good = Goods.get_by_id(2)
    #更新
    # good.click_num += 1
    # good.save()
    # Goods.update(click_num=Goods.click_num + 1).where(Goods.id == 1).execute()

    #删除
    # good.delete_instance()
    Goods.delete().where(Goods.id==2).execute()


if __name__ == "__main__":
    # save_model()

    # query_model()

    # update_model()

    good = Goods.select().where(Goods.price>1000).exists()
    print(good)

Beispiel #28
0
def modifyInfo():
    if request.method == 'GET':
        status = 0
        return render_template('user_page.html', status=status)
    else:
        user_account = session.get('user_account')
        user = Users.query.filter(Users.account == user_account).first()
        way = request.form.get('way')
        if way == 'password':
            password = request.form.get('password').strip()
            password1 = request.form.get('password1').strip()
            password2 = request.form.get('password2').strip()
            if (password == '') or (password1 == '') or (password2 == ''):
                status = 1
                return render_template('user_page.html',
                                       status=status,
                                       alert='Somthing empty',
                                       message='Please input password again!')
            elif user.password != password:
                status = 1
                return render_template('user_page.html',
                                       status=status,
                                       alert='old password wrong',
                                       message='Please input it again!')
            elif password1 != password2:
                status = 1
                return render_template('user_page.html',
                                       status=status,
                                       alert='passwords doesn\'t match',
                                       message='Please input it again!')
            else:
                user.password = password1
                db.session.commit()
                session.clear()
                status = 1
                return render_template('user_page.html',
                                       color='success',
                                       status=status,
                                       alert='Modify seccussfully',
                                       message='Please login again!')
        elif way == 'address':
            address = request.form.get('address').strip()
            if address == '':
                status = 1
                return render_template('user_page.html',
                                       status=status,
                                       alert='New address is empty',
                                       message='Please input it again!')
            else:
                user.address = address
                db.session.commit()
                status = 1
                return render_template('user_page.html',
                                       color='success',
                                       status=status,
                                       alert='Modify address successfully')
        elif way == 'Alia':
            alia = request.form.get('alia')
            alia1 = request.form.get('alia1')
            if (alia == '') or (alia1 == ''):
                status = 1
                return render_template('user_page.html',
                                       status=status,
                                       alert='Something empty!')
            elif alia != user.name:
                status = 1
                return render_template('user_page.html',
                                       status=status,
                                       alert='Old name is wrong!!',
                                       message='Please input it again.')
            else:
                check_user = Users.query.filter(Users.name == alia1).first()
                # check whether the name has already in the database
                if check_user:
                    status = 1
                    return render_template('user_page.html',
                                           status=status,
                                           alert='The name already existed!!',
                                           message='Please change a name.')
                else:
                    user.name = alia1
                    db.session.commit()
                    status = 1
                    return render_template(
                        'user_page.html',
                        status=status,
                        color='success',
                        alert='name modify successfully',
                        message='Please check it in the user info tab.')
        elif way == 'class':
            selected_good = request.form.get('good_name')
            class_name = request.form.get('good_class')
            # print(selected_good + '   ' + class_name)
            # Firstly, we add a new class if it didn't exist
            check_exist = Goods_class.query.filter(
                Goods_class.class_name == class_name).first()
            # Then get the data of the selected good
            good = Goods.query.filter(Goods.id == selected_good).first()
            if check_exist:
                class_id = check_exist.class_id
                good.class_id = class_id
                db.session.commit()
            else:
                # Add new class
                new_class = Goods_class(class_name=class_name)
                db.session.add(new_class)
                db.session.commit()
                # Modify the good's class
                good.class_id = Goods_class.query.filter(
                    Goods_class.class_name == class_name).first().class_id
                db.session.commit()
            return render_template('user_page.html',
                                   status=1,
                                   color='success',
                                   alert='Add class successfully。')
        elif way == 'add_good':
            good_name = request.form.get('good_name')
            good_desc = request.form.get('good_desc')
            good_price = request.form.get('good_price')
            picture_url = request.form.get('picture_url')
            new_good = Goods(good_name=good_name,
                             good_desc=good_desc,
                             good_price=good_price,
                             picture_url=picture_url)
            db.session.add(new_good)
            db.session.commit()
            return render_template('user_page.html',
                                   status=1,
                                   color='success',
                                   alert='Add good successfully。')
Beispiel #29
0
def trade_add(request):
    goods_top = Trade.objects.values('goods__id','goods__title').annotate(goods_count=Count('goods')).order_by('-goods_count')[:10]

    price1 = 0
    results = []
    if request.method == 'POST': # If the form has been submitted...
        form = TradeForm(request.POST) # A form bound to the POST data
        if form.is_valid(): # All validation rules pass
            # Process the data in form.cleaned_data
            # ...
            #return HttpResponseRedirect('/thanks/') # Redirect after POST

            #results = GClass.objects.filter(title__icontains=form.cleaned_data['goodstitle'])

            isOldTrade = False
            if int(form.cleaned_data["trade_pk"]) > 0:
                isOldTrade = True

            shop1 = None
            if int(form.cleaned_data["shop_pk"]) > 0:
                shop1 = Shop.objects.get(pk=form.cleaned_data["shop_pk"])
            else:
                shop1 = Shop(title=form.cleaned_data["shop"], type='mag')
                shop1.save()

            #gclass1 = None
            #if int(form.cleaned_data["gclass_pk"]) > 0:
            #    gclass1 = GClass.objects.get(pk=form.cleaned_data["gclass_pk"])
            #else:
            #    gclass1 = GClass(title=form.cleaned_data["gclass"], section=GSection.objects.get(pk=1)) #TODO GSection
            #    gclass1.save()

            goods1 = None
            if int(form.cleaned_data["gtitle_pk"]) > 0:
                goods1 = Goods.objects.get(pk=form.cleaned_data["gtitle_pk"])
                goods1.title = form.cleaned_data["gtitle"]
                goods1.ed = form.cleaned_data["ed"]
                #goods1.gclass = gclass1
                goods1.save()
            else:
                goods1 = Goods(title=form.cleaned_data["gtitle"], ed=form.cleaned_data["ed"])
                goods1.save()

            price1 = "%.2f" % ( float(form.cleaned_data['cost']) / float(form.cleaned_data['amount']) )

            if isOldTrade:
                trade1 = Trade.objects.get(pk=form.cleaned_data["trade_pk"])
            else:
                trade1 = Trade()

            trade1.user = request.user
            trade1.shop = shop1
            trade1.goods = goods1
            trade1.time = form.cleaned_data["time"]
            trade1.amount = form.cleaned_data["amount"]
            trade1.price = price1
            trade1.cost = form.cleaned_data["cost"]
            trade1.currency = form.cleaned_data["currency"]
            trade1.spytrade = form.cleaned_data["spytrade"]

            trade1.save()

            return HttpResponseRedirect("/")

    else:
        data = {'time': datetime.datetime.now, 'trade_pk': '0', 'shop_pk': '0', 'gclass_pk': '0', 'gtitle_pk': '0' }
        form = TradeForm(initial=data) # An unbound form

    return render_to_response('trade_add.html',
        {'price': price1, 'results': results, 'form': form, 'goods_top': goods_top},
        context_instance=RequestContext(request))
Beispiel #30
0
def get_item_by_id(id_):
    item = Goods.select().where(Goods.id == id_)
    return item[0]
Beispiel #31
0
def get_immed_heirs(parent_id, admin=True):
    items = Goods.select().where(Goods.parent_id == parent_id)
    res = [[item.name, item.id, item.amount, item.price] for item in items
           if item.amount > 0 or admin]
    return res
Beispiel #32
0
def create_tables():
    database.connect()
    database.create_tables([Goods, Admins, Orders_Info, Orders_Content],
                           safe=True)
    Goods.create(name='.BASE_CAT', amount=0)
    Goods.create(name='Браслеты', amount=100, parent_id=1)
    Goods.create(name='Значки', amount=75, parent_id=1)
    Goods.create(name='Кружки', amount=150, price=100, parent_id=1)
    Goods.create(name='Синие', amount=50, price=10, parent_id=2)
    Goods.create(name='Красные', amount=36, price=15, parent_id=2)
    Goods.create(name='Желтые', amount=14, price=20, parent_id=2)
    Goods.create(name='Жестяные', amount=30, price=17, parent_id=3)
    Goods.create(name='Деревянные', amount=45, price=13, parent_id=3)
    Admins.create(chat_id='1234')
    database.close()
Beispiel #33
0
def update_name(id_, name):
    Goods.select().where(Goods.id == id_)[0]
    query = Goods.update({Goods.name: name}).where(Goods.id == id_)
    query.execute()