Commit 2b0c9e45 authored by PJ Janse van Rensburg's avatar PJ Janse van Rensburg

Expand documentation: grouping views and adding links to the menu.

parent 18e0d317
......@@ -156,12 +156,9 @@ Customizing Built-in Views
****
The built-in `ModelView` class is great for getting started quickly. But, you'll want
to configure its functionality to suit your particular models. This is done by setting
values for the configuration attributes that are made available in the `ModelView` class.
To specify some global configuration parameters, you can subclass `ModelView` and use that
subclass when adding your models to the interface::
When inheriting from `ModelView`, values can be specified for numerous
configuration parameters. Use these to customize the views to suit your
particular models::
from flask_admin.contrib.sqla import ModelView
......@@ -287,6 +284,28 @@ To **enable csv export** of the model view::
This will add a button to the model view that exports records, truncating at :attr:`~flask_admin.model.BaseModelView.export_max_rows`.
Grouping Views
==============
When adding a view, specify a value for the `category` parameter
to group related views together in the menu::
admin.add_view(UserView(User, db.session, category="Team"))
admin.add_view(ModelView(Role, db.session, category="Team"))
admin.add_view(ModelView(Permission, db.session, category="Team"))
This will create a top-level menu item named 'Team', and a drop-down containing
links to the three views.
To nest related views within these drop-downs, use the `add_sub_category` method::
admin.add_sub_category(name="Links", parent_name="Team")
And to add arbitrary hyperlinks to the menu:
admin.add_link(MenuLink(name='Home Page', url='/', category='Links'))
Adding Your Own Views
=====================
......
......@@ -783,7 +783,7 @@ class BaseModelView(BaseView, ActionsMixin):
:param name:
View name. If not provided, will use the model class name
:param category:
View category
Optional category name, for grouping views in the menu
:param endpoint:
Base endpoint. If not provided, will use the model name.
:param url:
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment