简体   繁体   中英

Flask appbuilder how to use existing model to create a new model and save into DB

Basically I have model A and B.

class A(ModelView):
datamodel = SQLAInterface(Tabel_A)

and

class B(ModelView):
datamodel = SQLAInterface(Table_B)

A has a action like:

@action("mularchive", "Archieve", "Archieve all Really?", "fa-rocket", single=False)
def mularchive(self, items):
    self.update_redirect()
    for item in items:
        new_item = item.__class__()
        new_item.name = item.name
        B.add(new_item)
    return redirect(self.get_redirect())

So I'm expect object b will save into table B. But this is not working and it complain about

AttributeError: 'Table A' object has no attribute 'method_permission_name'

please help, I'm new to flask appbuilder and python... not sure where I made mistake.

for item in items
    b = B(name = item.name)
    db.session.add(b)
    db.session.commit()
self.update_redirect()
return redirect(self.get_redirect())

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM