If you are using the MongoEngine backend, Flask-Admin supports GridFS-backed image- and file uploads, done through WTForms fields. Documentation can be found
at :mod:`flask_admin.contrib.mongoengine.fields`.
If you just want to manage static files in a directory, without tying them to a database model, then
rather use the handy :ref:`File-Admin<file-admin>` plugin.
Initialisation
Initialisation
---------------
---------------
****
As an alternative to passing a Flask application object to the Admin constructor, you can also call the
As an alternative to passing a Flask application object to the Admin constructor, you can also call the
:meth:`~flask_admin.base.Admin.init_app` function, after the Admin instance has been initialized::
:meth:`~flask_admin.base.Admin.init_app` function, after the Admin instance has been initialized::
...
@@ -10,10 +112,11 @@ As an alternative to passing a Flask application object to the Admin constructor
...
@@ -10,10 +112,11 @@ As an alternative to passing a Flask application object to the Admin constructor
# Add views here
# Add views here
admin.init_app(app)
admin.init_app(app)
****
Localization with Flask-Babelex
Localization with Flask-Babelex
------------------------------------------
------------------------------------------
****
Enabling localization is relatively simple.
Enabling localization is relatively simple.
#. Install `Flask-BabelEx <http://github.com/mrjoes/flask-babelex/>`_ to do the heavy
#. Install `Flask-BabelEx <http://github.com/mrjoes/flask-babelex/>`_ to do the heavy
...
@@ -49,11 +152,12 @@ Enabling localization is relatively simple.
...
@@ -49,11 +152,12 @@ Enabling localization is relatively simple.
If the builtin translations are not enough, look at the `Flask-BabelEx documentation <https://pythonhosted.org/Flask-BabelEx/>`_
If the builtin translations are not enough, look at the `Flask-BabelEx documentation <https://pythonhosted.org/Flask-BabelEx/>`_
to see how you can add your own.
to see how you can add your own.
****
Handling Foreign Key relations inline
Handling Foreign Key relations inline
--------------------------------------------
--------------------------------------------
****
Many-to-many relations
Many-to-many relations
----------------------------------
----------------------------------
...
@@ -64,6 +168,8 @@ Many-to-many relations
...
@@ -64,6 +168,8 @@ Many-to-many relations
Managing Files & Folders
Managing Files & Folders
--------------------------------
--------------------------------
****
Flask-Admin comes with another handy battery - file admin. It gives you the ability to manage files on your server
Flask-Admin comes with another handy battery - file admin. It gives you the ability to manage files on your server
(upload, delete, rename, etc).
(upload, delete, rename, etc).
...
@@ -89,11 +195,11 @@ Sample screenshot:
...
@@ -89,11 +195,11 @@ Sample screenshot:
You can disable uploads, disable file or directory deletion, restrict file uploads to certain types and so on.
You can disable uploads, disable file or directory deletion, restrict file uploads to certain types and so on.
Check :mod:`flask_admin.contrib.fileadmin` documentation on how to do it.
Check :mod:`flask_admin.contrib.fileadmin` documentation on how to do it.
****
Managing geographical models
Managing geographical models
--------------------------------------
--------------------------------------
****
GeoAlchemy backend
GeoAlchemy backend
If you want to store spatial information in a GIS database, Flask-Admin has
If you want to store spatial information in a GIS database, Flask-Admin has
...
@@ -173,11 +279,11 @@ If you have any ideas or suggestions, make a pull request!
...
@@ -173,11 +279,11 @@ If you have any ideas or suggestions, make a pull request!
Adding CSRF validation will require overriding the :class:`flask_admin.form.BaseForm` by using :attr:`flask_admin.model.BaseModelView.form_base_class`.
Adding CSRF validation will require overriding the :class:`flask_admin.form.BaseForm` by using :attr:`flask_admin.model.BaseModelView.form_base_class`.
WTForms >=2::
WTForms >=2::
...
@@ -298,11 +405,14 @@ For WTForms 1, you can use use Flask-WTF's Form class::
...
@@ -298,11 +405,14 @@ For WTForms 1, you can use use Flask-WTF's Form class::
app.run(debug=True)
app.run(debug=True)
****
Using different database backends
.. _database-backends:
Using Different Database Backends
----------------------------------------
----------------------------------------
****
The purpose of Flask-Admin is to help you manage your data. For this, it needs some database backend in order to be
The purpose of Flask-Admin is to help you manage your data. For this, it needs some database backend in order to be
able to access that data in the first place. At present, there are five different backends for you to choose
able to access that data in the first place. At present, there are five different backends for you to choose
from, depending on which database you would like to use for your application.
from, depending on which database you would like to use for your application.
...
@@ -335,11 +445,11 @@ are dedicated to helping you through this process. See :doc:`model_guidelines`.
...
@@ -335,11 +445,11 @@ are dedicated to helping you through this process. See :doc:`model_guidelines`.
.. _MongoEngine: http://mongoengine.org/
.. _MongoEngine: http://mongoengine.org/
.. _MongoDB: http://www.mongodb.org/
.. _MongoDB: http://www.mongodb.org/
****
Migrating from Django
Migrating from Django
-------------------------
-------------------------
****
If you are used to `Django <https://www.djangoproject.com/>`_ and the *django-admin* package, you will find
If you are used to `Django <https://www.djangoproject.com/>`_ and the *django-admin* package, you will find
Flask-Admin to work slightly different from what you would expect.
Flask-Admin to work slightly different from what you would expect.
...
@@ -469,5 +579,28 @@ and then point your class to this new template::
...
@@ -469,5 +579,28 @@ and then point your class to this new template::
For list of available template blocks, check :doc:`templates`.
For list of available template blocks, check :doc:`templates`.
Adding a Redis console
--------------------------
****
Overriding the Form Scaffolding
---------------------------------
****
If you don't want to the use the built-in Flask-Admin form scaffolding logic, you are free to roll your own
by simply overriding :meth:`~flask_admin.model.base.scaffold_form`. For example, if you use
`WTForms-Alchemy <https://github.com/kvesteri/wtforms-alchemy>`_, you could put your form generation code
into a `scaffold_form` method in your `ModelView` class.
For SQLAlchemy, if the `synonym_property` does not return a SQLAlchemy field, then Flask-Admin won't be able to figure out what to
do with it, so it won't generate a form field. In this case, you would need to manually contribute your own field::