2017-12-20 14 views
1

私はPython 2.7とPyrebase(Firebaseデータベースと通信するためのパッケージとして)を使用しています。 データベースに新しくプッシュされたオブジェクトのkey()を取得しようとしています。私はNode.jsのでこれに多くの時間をしましたが、私はここのPython 2.7 でそれを行うにはいくつかの助けを必要とする私のAPIです:push(firefox2.7)の後にfirebaseキーを取得

@APP.route('/api/product', methods = ['POST']) 
def products(): 
    product_details = { 
     "title": request.form['title'], 
     "description": request.form['description'] 
    } 
    new_product = DB.push("product").push(product_details) 
    print new_product.get().key() 

    return json.dumps(apiResponse.success(product_details)) 

オブジェクトをデータベースに挿入されますが、私は見当がつかないその鍵を取得する方法。 node.jsでは、私は約束を使用し、挿入後に鍵を取得します。

PS:私はPyrebaseパッケージ

答えて

0

を使用するので、私は.ref()を使用することはできません私は私のコードにこれを追加しました: rec = DB.child("product").push(product_details)とこのように、私は私のコードは次のようになり、key.Soを得ることができたが:

@APP.route('/api/product', methods = ['POST']) 
def products(): 
    product_details = { 
     "title": request.form['title'], 
     "description": request.form['description'] 
    } 
    DB.child("product").push(product_details) 
    rec = DB.child("product").push(product_details) 
    DB.child("users").child(owner_details['uid']).child('products').update({rec['name']: "true"}) 
    return json.dumps(apiResponse.success(product_details)) 
関連する問題