0

I am curious about how to approach dynamically updating Flask-Admin lists. I can toggle various settings with _handle_view, but changing column_lists and filter_lists doesn't seem to be an option. Example view:

    class MyView(sqla.ModelView):
        column_list = ['first_name', 'last_name', 'phone', 'email']
        column_searchable_list = ['first_name', 'last_name', 'phone',email']
        column_filters = ['first_name', 'last_name', 'email']
        can_create = True

    def is_accessible(self):
        if current_user.is_authenticated:
            return current_user.is_admin or current_user.has_permission('staff')

    def inaccessible_callback(self, name, **kwargs):
        flash('Authentication Required')
        return redirect(url_for('main.index'))

    def _handle_view(self, name, **kwargs):
        if not current_user.is_admin:
            self.can_create = False
            self.column_filters = ['first_name']

The above view alters the create option (or delete/edit/ boolean options in flask-admin), but _handle_view will not overwrite any of the list options like column_filters or column_list. At least as far as I can tell.

Anyone have experience with this or can point me in the right direction?

Joshraz
  • 43
  • 3
  • Or alternatively is there a way in flask-admin to create custom column_filters based on queries? FilterEquals(User.office_id, name="Office", options=[(str(office[1]), office.office_name) for office in db.session.query(Office.id, Office.office_name).all()]) – Joshraz May 18 '16 at 20:26
  • Did you ever solve this..? – tiktuk May 30 '16 at 20:26
  • Unfortunately, I did not. I ended up overriding a few of the create_views/edit_views in my ModelView for where I needed it. I'm not sure its the best strategy, but I'm just working on some basic functionality now. I've also found using model functions to return data to be incredibly helpful. – Joshraz Jun 01 '16 at 15:32
  • Thanks. I got [this answer](http://stackoverflow.com/a/37554001) yesterday. It might apply to this case as well. – tiktuk Jun 01 '16 at 19:43

0 Answers0