使用Python将地图添加到Firestore文档

时间:2020-01-30 08:40:25

标签: python google-cloud-firestore

因此,我试图将map添加到Firestore中已写入数据的现有文档中。我发现了如何在不使用merge覆盖现有数据的情况下添加数据,但是,我的数据已注册为string

这是应该推送数据的一段代码:

def sendCustomer(self):
    db.collection("parameters").document("new_mlt_ben").set(self.__dict__, merge=True)

它用于只有一个参数Customers的自定义对象name

class Customers(object):
    def __init__(self):
        self.name = [] #When I push the obj in the doc, name contain only one name,
                       #it is set as a list because I use it as a list on another function that get all
                       #map from the "new_mlt_ben" wich are customers name on that context

这是我实际使用该函数的代码段:

@app.route("/customer", methods=['GET', 'POST'])
def addCustomer():
    form = AjouterCustomer() #WTForm generated form
    if form.validate_on_submit():
        customer = Customers() #I create an empty customer obj
        customer.setName(form.name.data) #I set the name with the user input
        try:
            customer.sendCustomer() #I push the obj
            flash("Add with success", 'success') #Woohoo it worked
        except ZeroDivisionError:
            flash("Bip bap boop it's broken", 'danger') #Woopsi
        return redirect(url_for('ajouter'))
    return render_template('ajouter.html', title='Ajouter customer', form=form)

TL; DR

我想在文档customer.name中将new_mlt_ben添加为map,但它已注册为string

感谢您的阅读!

1 个答案:

答案 0 :(得分:1)

所以我找到了解决方法,这是想知道的thoose的解决方案:

<BootstrapTable data={this.state.blogs} version="4" striped hover pagination search options={this.options}>