Editable list view - Flask-Admin
I’ve been doing a lot of work in Flask-Admin lately, and the thing that kept bugging me was editing a single field. I’d spot a typo in the list, click into the record’s edit form, change one field, save, and go back. That’s a lot of clicks for a one-character fix.
So I opened an issue proposing edits straight from the list view (#755) and then built it (#756, merged today).
It’s a new column_editable_list property on the ModelView:
class UserView(ModelView):
column_editable_list = ['name', 'email']
Those columns become click-to-edit in the list. Click a cell, type, hit enter, and it saves over AJAX with X-editable. Works across the SQLAlchemy, MongoEngine, and Peewee backends, and posts a CSRF token with each edit.
The messy part was the data handling. My first attempt rendered a form field for every row and tried to process the whole page as a WTForms FieldList. That got out of hand fast. What worked was wrapping each field on its own and reusing the existing update_model method to save, so validation and the record-not-found case were already handled. That fix came out of the code review on the PR.
Update: this one stuck around, and I ended up maintaining it for a while afterward: an XSS fix to HTML-escape the editable values (#1002), nullable enums and blank selects (#1009), and eventually a rewrite that builds a form per input (#1160, #1162). A bunch of smaller ones in between too. column_editable_list is still in Flask-Admin.