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;