Commit c6718591 authored by Petrus J.v.Rensburg's avatar Petrus J.v.Rensburg

Customising builtin views: File & Image fields.

parent c3b00fcb
Advanced Advanced
=========== ===========
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::
...@@ -11,7 +11,7 @@ As an alternative to passing a Flask application object to the Admin constructor ...@@ -11,7 +11,7 @@ As an alternative to passing a Flask application object to the Admin constructor
admin.init_app(app) admin.init_app(app)
Enabling localization Enabling localization
----------- ----------------------
Flask-Admin makes it possible for you to serve your application in more than one language. To do this, it makes use of Flask-Admin makes it possible for you to serve your application in more than one language. To do this, it makes use of
the `Flask-BabelEx <http://github.com/flask-admin/flask-babelex/>`_ package for handling translations. This package is a the `Flask-BabelEx <http://github.com/flask-admin/flask-babelex/>`_ package for handling translations. This package is a
fork of the popular `Flask-Babel <http://github.com/mitshuhiko/flask-babel/>`_ package, with the following features: fork of the popular `Flask-Babel <http://github.com/mitshuhiko/flask-babel/>`_ package, with the following features:
...@@ -53,13 +53,15 @@ the application should be accessible at: ...@@ -53,13 +53,15 @@ the application should be accessible at:
`http://localhost:5000/admin/userview/?lang=fr <http://localhost:5000/admin/userview/?lang=fr>`_. `http://localhost:5000/admin/userview/?lang=fr <http://localhost:5000/admin/userview/?lang=fr>`_.
Handling Foreign Key relations inline Handling Foreign Key relations inline
----------- --------------------------------------------
Many-to-many relations Many-to-many relations
------------ ----------------------------------
.. _file-admin:
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).
...@@ -87,7 +89,7 @@ You can disable uploads, disable file or directory deletion, restrict file uploa ...@@ -87,7 +89,7 @@ You can disable uploads, disable file or directory deletion, restrict file uploa
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
...@@ -107,7 +109,7 @@ Notable features: ...@@ -107,7 +109,7 @@ Notable features:
- Works with a `Geometry`_ SQL field that is integrated with `Shapely`_ objects - Works with a `Geometry`_ SQL field that is integrated with `Shapely`_ objects
Getting Started Getting Started
^^^^^^^^^^^^^ ^^^^^^^^^^^^^^^^^^
GeoAlchemy is based on SQLAlchemy, so you'll need to complete the "getting started" GeoAlchemy is based on SQLAlchemy, so you'll need to complete the "getting started"
directions for SQLAlchemy backend first. For GeoAlchemy, you'll also need a directions for SQLAlchemy backend first. For GeoAlchemy, you'll also need a
...@@ -128,7 +130,7 @@ To use the v4 of their API (the default is v3)::: ...@@ -128,7 +130,7 @@ To use the v4 of their API (the default is v3):::
providers, make a pull request! providers, make a pull request!
Creating simple model Creating simple model
^^^^^^^^^^^^^^ ^^^^^^^^^^^^^^^^^^^^^^^^
GeoAlchemy comes with a `Geometry`_ field that is carefully divorced from the GeoAlchemy comes with a `Geometry`_ field that is carefully divorced from the
`Shapely`_ library. Flask-Admin will use this field so that there are no `Shapely`_ library. Flask-Admin will use this field so that there are no
...@@ -170,7 +172,7 @@ If you have any ideas or suggestions, make a pull request! ...@@ -170,7 +172,7 @@ If you have any ideas or suggestions, make a pull request!
Customising builtin forms via form rendering rules Customising builtin forms via form rendering rules
-------------------- --------------------------------------------------------
Before version 1.0.7, all model backends were rendering the *create* and *edit* forms Before version 1.0.7, all model backends were rendering the *create* and *edit* forms
using a special Jinja2 macro, which was looping over the fields of a WTForms form object and displaying using a special Jinja2 macro, which was looping over the fields of a WTForms form object and displaying
...@@ -228,7 +230,7 @@ Form Rendering Rule Description ...@@ -228,7 +230,7 @@ Form Rendering Rule Description
======================================================= ======================================================== ======================================================= ========================================================
Enabling CSRF Validation Enabling CSRF Validation
^^^^^^^^^^^^^^^^^ ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
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::
...@@ -297,7 +299,7 @@ For additional documentation, check :mod:`flask_admin.form.rules` module source ...@@ -297,7 +299,7 @@ For additional documentation, check :mod:`flask_admin.form.rules` module source
look at the `forms example <https://github.com/flask-admin/flask-admin/tree/master/examples/forms>`_ on GitHub. look at the `forms example <https://github.com/flask-admin/flask-admin/tree/master/examples/forms>`_ on GitHub.
Using different 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
...@@ -334,7 +336,7 @@ are dedicated to helping you through this process. See :doc:`model_guidelines`. ...@@ -334,7 +336,7 @@ are dedicated to helping you through this process. See :doc:`model_guidelines`.
Implementing your own authentication Implementing your own authentication
--------------------------------- ----------------------------------------------------
Flask-Admin does not make any assumptions about the authentication system you might be using. So, by default, the admin Flask-Admin does not make any assumptions about the authentication system you might be using. So, by default, the admin
interface is completely open. interface is completely open.
...@@ -423,7 +425,7 @@ This guide will help you to get acquainted with the Flask-Admin library. It is a ...@@ -423,7 +425,7 @@ This guide will help you to get acquainted with the Flask-Admin library. It is a
knowledge of `Flask <http://flask.pocoo.org/>`_ . knowledge of `Flask <http://flask.pocoo.org/>`_ .
Design Philosophy Design Philosophy
************** ****************************
In general, Django and *django-admin* strives to make life easier by implementing sensible defaults. So a developer In general, Django and *django-admin* strives to make life easier by implementing sensible defaults. So a developer
will be able to get an application up in no time, but it will have to conform to most of the defaults. Of course it will be able to get an application up in no time, but it will have to conform to most of the defaults. Of course it
...@@ -447,7 +449,7 @@ Due to Flask-Admin supporting more than one ORM (SQLAlchemy, MongoEngine, Peewee ...@@ -447,7 +449,7 @@ Due to Flask-Admin supporting more than one ORM (SQLAlchemy, MongoEngine, Peewee
free to mix different model types into one application by instantiating appropriate CRUD classes. free to mix different model types into one application by instantiating appropriate CRUD classes.
Getting started Getting started
************** ****************************
At the basis of Flask-Admin is the idea that you can add components to your admin interface by declaring a separate At the basis of Flask-Admin is the idea that you can add components to your admin interface by declaring a separate
class for each component, and then adding a method to that class for every view that should be associated to the class for each component, and then adding a method to that class for every view that should be associated to the
...@@ -558,7 +560,7 @@ and then point your class to this new template:: ...@@ -558,7 +560,7 @@ 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`.
Tips and hints Tips and hints
************* ***************************
1. Programming with Flask-Admin is not very different from normal application development - write some views and expose 1. Programming with Flask-Admin is not very different from normal application development - write some views and expose
them to the user, using templates to create a consistent user experience. them to the user, using templates to create a consistent user experience.
......
...@@ -68,6 +68,18 @@ For a faster editing experience, make some of the columns editable in the list v ...@@ -68,6 +68,18 @@ For a faster editing experience, make some of the columns editable in the list v
Common Form view options Common Form view options
************************** **************************
You can restrict the values of a text-field by specifying a list of choices::
form_choices = {
'title': [
('MR', 'Mr'),
('MRS', 'Mrs'),
('MS', 'Ms'),
('DR', 'Dr'),
('PROF', 'Prof.')
]
}
To remove some fields from the forms:: To remove some fields from the forms::
form_excluded_columns = ('last_name', 'email') form_excluded_columns = ('last_name', 'email')
...@@ -199,4 +211,12 @@ functionality by including the necessary CKEditor javascript on the `create` and ...@@ -199,4 +211,12 @@ functionality by including the necessary CKEditor javascript on the `create` and
File & Image fields File & Image fields
******************* *******************
For handling File & Image fields, have a look a the example at
https://github.com/flask-admin/Flask-Admin/tree/master/examples/forms.
You'll need to specify an upload directory, and then use either `FileUploadField` or
`ImageUploadField` to override the field in question.
If you just want to manage static files, without tying them to a database model, then
rather use the :ref:`File-Admin<file-admin>` plugin.
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