Flask-Admin does not make any assumptions about the authentication system you might be using. So, by default, the admin
interface is completely open.
To control access to the admin interface, you can specify an `is_accessible` method when extending the `BaseView` class.
To control access to the admin interface, you can specify an *is_accessible* method when extending the *BaseView* class.
So, for example, if you are using Flask-Login for authentication, the following will ensure that only logged-in users
have access to the view in question::
...
...
@@ -171,7 +172,7 @@ administrative interface. If a user does not have access to a particular view, t
Generating URLs
---------------
Internally, view classes work on top of Flask blueprints, so you can use `url_for` with a dot
Internally, view classes work on top of Flask blueprints, so you can use *url_for* with a dot
prefix to get the URL for a local view::
from flask import url_for
...
...
@@ -189,12 +190,12 @@ prefix to get the URL for a local view::
If you want to generate a URL for a particular view method from outside, the following rules apply:
1. You can override the endpoint name by passing `endpoint` parameter to the view class constructor::
1. You can override the endpoint name by passing *endpoint* parameter to the view class constructor::
admin = Admin(app)
admin.add_view(MyView(endpoint='testadmin'))
In this case, you can generate links by concatenating the view method name with an endpoint::
In this case, you can generate links by concatenating the view method name with an endpoint::
url_for('testadmin.index')
...
...
@@ -202,15 +203,14 @@ In this case, you can generate links by concatenating the view method name with
url_for('myview.index')
3. For model-based views the rules differ - the model class name should be used, if an endpoint name is not provided.
Model-based views will be explained in the next section.
3. For model-based views the rules differ - the model class name should be used if an endpoint name is not provided. Model-based views will be explained in the next section.
Model Views
-----------
Model views allow you to add dedicated admin pages for each of the models in your database. Do this by creating
instances of the `ModelView` class, which you can import from one of Flask-Admin's built-in ORM backends. An example
instances of the *ModelView* class, which you can import from one of Flask-Admin's built-in ORM backends. An example
is the SQLAlchemy backend, which you can use as follows::
from flask.ext.admin.contrib.sqla import ModelView
...
...
@@ -220,13 +220,13 @@ is the SQLAlchemy backend, which you can use as follows::
admin = Admin(app)
admin.add_view(ModelView(User, db.session))
This creates an admin page for the `User` model. By default, the list view looks like::
This creates an admin page for the *User* model. By default, the list view looks like
.. image:: images/quickstart/quickstart_4.png
:width: 640
:target: ../_images/quickstart_4.png
To customize these model views, you have two options: Either you can override the public properties of the `ModelView`
To customize these model views, you have two options: Either you can override the public properties of the *ModelView*
class, or you can override its methods.
For example, if you want to disable model creation and only show certain columns in the list view, you can do
...
...
@@ -251,8 +251,8 @@ something like::
admin.add_view(MyView(db.session))
Overriding form elements can be a bit trickier, but it is still possible. Here's an example of
how to set up a form that includes a column named ``status`` that allows only predefined values and
therefore should use a ``SelectField``::
how to set up a form that includes a column named *status* that allows only predefined values and
therefore should use a *SelectField*::
from wtforms.fields import SelectField
...
...
@@ -305,8 +305,7 @@ Examples
Flask-Admin comes with few examples:
- `Simple administrative interface <https://github.com/MrJoes/Flask-Admin/tree/master/examples/simple>`_ with custom
administrative views
- `Simple administrative interface <https://github.com/MrJoes/Flask-Admin/tree/master/examples/simple>`_ with custom administrative views
- `SQLAlchemy model example <https://github.com/MrJoes/Flask-Admin/tree/master/examples/sqla>`_
- `Flask-Login integration example <https://github.com/MrJoes/Flask-Admin/tree/master/examples/auth>`_