{"action":"created","issue":{"url":"https://api.github.com/repos/flask-admin/flask-admin/issues/998","labels_url":"https://api.github.com/repos/flask-admin/flask-admin/issues/998/labels{/name}","comments_url":"https://api.github.com/repos/flask-admin/flask-admin/issues/998/comments","events_url":"https://api.github.com/repos/flask-admin/flask-admin/issues/998/events","html_url":"https://github.com/flask-admin/flask-admin/issues/998","id":101579712,"number":998,"title":"Example for Custom List Action","user":{"login":"boolbag","id":7551671,"avatar_url":"https://avatars.githubusercontent.com/u/7551671?v=3","gravatar_id":"","url":"https://api.github.com/users/boolbag","html_url":"https://github.com/boolbag","followers_url":"https://api.github.com/users/boolbag/followers","following_url":"https://api.github.com/users/boolbag/following{/other_user}","gists_url":"https://api.github.com/users/boolbag/gists{/gist_id}","starred_url":"https://api.github.com/users/boolbag/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/boolbag/subscriptions","organizations_url":"https://api.github.com/users/boolbag/orgs","repos_url":"https://api.github.com/users/boolbag/repos","events_url":"https://api.github.com/users/boolbag/events{/privacy}","received_events_url":"https://api.github.com/users/boolbag/received_events","type":"User","site_admin":false},"labels":[],"state":"open","locked":false,"assignee":null,"milestone":null,"comments":5,"created_at":"2015-08-18T06:07:50Z","updated_at":"2015-10-18T00:36:15Z","closed_at":null,"body":"Greetings, Python database heads!\r\n\r\nWhen making database interfaces, on each row I usually add several custom buttons. For instance, on this image, you can see that apart from Edit and Delete, there is \"Where?\" and \"+Movie\". Each interface ends up needing some custom buttons (\"Duplicate\", \"Preview\", etc.)\r\n\r\n![actions](https://cloud.githubusercontent.com/assets/7551671/9323075/6db81e82-45d0-11e5-94dd-c6fc66552ee2.jpg)\r\n\r\nThe list on the image is from a CRUD framework I made years ago in php (kss kss....)\r\nNow that all my new development is in Python, I am very excited about exploring flask-admin... and not having to reinvent the wheel! It looks like the job has already been done beautifully.\r\n\r\nSo now I'm trying to understand how to add these custom buttons / actions in flask-admin. In the docs, I saw some sample code about the very useful [Batch Actions](https://flask-admin.readthedocs.org/en/latest/advanced/#customizing-batch-actions), which would appear not on each row, but within the \"With Selected\" menu. \r\n![actions-bulk](https://cloud.githubusercontent.com/assets/7551671/9323141/3af3b226-45d1-11e5-9837-2a667be6717d.jpg)\r\n\r\nTo add actions at the row level, I found a couple of short [posts in the issue tracker](https://github.com/flask-admin/flask-admin/issues/155) but no detailed explanation either in the docs or in the [examples section of the repo](https://github.com/flask-admin/flask-admin/tree/master/examples).\r\n\r\nFor me adding custom actions next to Edit and Delete is a key need for my database interfaces.\r\n\r\n![actions-list](https://cloud.githubusercontent.com/assets/7551671/9323231/67001fac-45d2-11e5-85dc-e1249c497f6a.png)\r\n\r\nflask-admin is really rich (yum), but that makes it quite a learning curve when considering all the other components it interacts with.\r\n\r\nIs there a chance that someone for whom adding a custom action is a \"piece of cake\" would consider adding an example to the [examples section](https://github.com/flask-admin/flask-admin/tree/master/examples), or even in the docs?\r\n\r\nIn advance, huge thanks!!!"},"comment":{"url":"https://api.github.com/repos/flask-admin/flask-admin/issues/comments/148963891","html_url":"https://github.com/flask-admin/flask-admin/issues/998#issuecomment-148963891","issue_url":"https://api.github.com/repos/flask-admin/flask-admin/issues/998","id":148963891,"user":{"login":"boolbag","id":7551671,"avatar_url":"https://avatars.githubusercontent.com/u/7551671?v=3","gravatar_id":"","url":"https://api.github.com/users/boolbag","html_url":"https://github.com/boolbag","followers_url":"https://api.github.com/users/boolbag/followers","following_url":"https://api.github.com/users/boolbag/following{/other_user}","gists_url":"https://api.github.com/users/boolbag/gists{/gist_id}","starred_url":"https://api.github.com/users/boolbag/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/boolbag/subscriptions","organizations_url":"https://api.github.com/users/boolbag/orgs","repos_url":"https://api.github.com/users/boolbag/repos","events_url":"https://api.github.com/users/boolbag/events{/privacy}","received_events_url":"https://api.github.com/users/boolbag/received_events","type":"User","site_admin":false},"created_at":"2015-10-18T00:36:15Z","updated_at":"2015-10-18T00:36:15Z","body":"@xmm \r\n\r\nThank you so much for your kind reply... Learning heaps!\r\n\r\nA. I hadn't noticed `admin_view`  in the documentation, that looks tremendously helpful. Looks like using `admin_view.model.__tablename__` I might be able to issue some raw SQL.\r\n\r\nThis makes me wonder how you became so skilled at working with flask-admin! Did you find learning resources outside of the repo and the documentation?\r\n\r\nB. Love your idea of making a `my_admin_helper` file with some custom queries. You suggest something like `return db.session.query(...)`. db is unknown in `my_admin_helper` but defined in `flaskadmin.py`, which imports `my_admin_helper`... To avoid cross-dependencies, moved the app creation and `db = SQLAlchemy(app)` to a `create_app` script imported by both flaskadmin.py and my_admin_helper.py. That seems to work, is that what you would do?\r\n\r\nC. While what you suggest is hugely interesting, my goals are a little different. Within `{% block list_row_actions %}`, I want to add a link or button. This button should open a view that shows the result of a custom query. \r\n\r\nMaking up an example, next to the Edit and Delete icons, there would be a 'SHOW THIS USER'S SUBSCRIPTIONS' link. That link would pass the `admin_view.model.__tablename__` and `get_pk_value(row)` parameters to a function that builds the query. Then the results of the query are displayed in a view.\r\n\r\nThe picture at the very top of the original post gives you an idea of possible actions. \r\n\r\nIf I can figure this out this will open the door to a lot of things I'd like to add. I'm sure it would be useful to loads of people so if I can understand it I'd like to add a gist for others on the same track. \r\n\r\nThank you again for your tremendous help. My flask-admin experiments have been stuck for weeks and it's a big relief to be moving forward."}}