Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Submit feedback
Sign in
Toggle navigation
F
flask-admin
Project
Project
Details
Activity
Releases
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Board
Labels
Milestones
JIRA
JIRA
Merge Requests
0
Merge Requests
0
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Commits
Issue Boards
Open sidebar
Python-Dev
flask-admin
Commits
7bb7c4af
Commit
7bb7c4af
authored
Aug 01, 2015
by
Emve Dev
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Docs: added customizing actions section
parent
3cbca053
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
29 additions
and
0 deletions
+29
-0
advanced.rst
doc/advanced.rst
+29
-0
No files found.
doc/advanced.rst
View file @
7bb7c4af
...
...
@@ -492,3 +492,32 @@ do with it, so it won't generate a form field. In this case, you would need to m
form_class.extra = TextField('Extra')
return form_class
Customizing Batch Actions
-------------------------
If you want to have other batch actions in list view besides the delete action, you have to define a new function and wrap it
in `@action` decorator. The `action` decorator has three parameters: `name`, `text`, `confirmation`. The wrapped
function must receive only one parameter - `ids`::
from flask_admin.actions import action
class UserView(ModelView):
@action('approve', 'Approve', 'Are you sure you want to approve selected users?')
def action_approve(self, ids):
try:
query = User.query.filter(User.id.in_(ids))
count = 0
for user in query.all():
if user.approve():
count += 1
flash(ngettext('User was successfully approved.',
'%(count)s users were successfully approved.',
count,
count=count))
except Exception as ex:
if not self.handle_view_exception(ex):
raise
flash(gettext('Failed to approve users. %(error)s', error=str(ex)), 'error')
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment