简体   繁体   中英

How to edit flask-admin to support multi tenancy?

I'm using Flask-peewee, looking for a way to give permission to admins, I'd like to make a multi tenancy admin dashboard.

I have made for displaying deals:

class DealsAdmin(ModelAdmin):
    columns = ('deal_name', 'deal_desc', 'created_on')
    exclude = ('created_on','merchand_id')

    def get_query(self):
        loggedin_username=auth.get_logged_in_user()
        merchant=Merchant.select().where(Merchant.id == loggedin_username).get()
        return self.model.select().where(self.model.merchand_id == loggedin_username)

So now I'd like to keep the loggedinuserid for Merchant id when they want to edit forms.

在此处输入图片说明

*Edit on image text: Merchant_id must be the auth.loggedinid as default

Remove the field from being displayed in the form, then hook into on_model_change:

class MyDealModelView(ModelView):
    form_excluded_columns = ('merchant_id',)

    def on_model_change(form, model, is_created):
        model.merchant_id = login.current_user.merchant_id;

http://flask-admin.readthedocs.org/en/latest/api/mod_model/#flask.ext.admin.model.BaseModelView.on_model_change

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