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
c3b00fcb
Commit
c3b00fcb
authored
Jun 28, 2015
by
Petrus J.v.Rensburg
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Customising builtin views: Rich-Text fields.
parent
55a714da
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
53 additions
and
14 deletions
+53
-14
customising_builtin_views.rst
doc/customising_builtin_views.rst
+53
-14
No files found.
doc/customising_builtin_views.rst
View file @
c3b00fcb
...
@@ -74,9 +74,12 @@ To remove some fields from the forms::
...
@@ -74,9 +74,12 @@ To remove some fields from the forms::
To specify arguments for rendering the WTForms fields::
To specify arguments for rendering the WTForms fields::
form_args = dict(
form_args = {
name=dict(label='First Name', validators=[required()])
'name': {
)
'label': 'First Name',
'validators': [required()]
}
}
Or, to go one level deeper, you can specify arguments for the widgets used to
Or, to go one level deeper, you can specify arguments for the widgets used to
render those fields. For example::
render those fields. For example::
...
@@ -98,16 +101,6 @@ related models loaded via ajax, using::
...
@@ -98,16 +101,6 @@ related models loaded via ajax, using::
}
}
}
}
Image fields
---------------
HTML fields
---------------
Overriding the default templates
Overriding the default templates
---------------------------------
---------------------------------
...
@@ -160,4 +153,50 @@ It is relatively easy to add support for different database backends (Mongo, etc
...
@@ -160,4 +153,50 @@ It is relatively easy to add support for different database backends (Mongo, etc
class and implementing database-related methods.
class and implementing database-related methods.
Please refer to :mod:`flask_admin.contrib.sqla` documentation on how to customize the behavior of model-based
Please refer to :mod:`flask_admin.contrib.sqla` documentation on how to customize the behavior of model-based
administrative views.
administrative views.
\ No newline at end of file
Replacing specific form fields
------------------------------------------
Individual form fields can be replaced completely by specifying the `form_overrides` attribute.
You can use this to add a rich text editor, or to handle
file / image uploads that need to be tied to a field in one of your models.
Rich-text fields
**********************
To handle complicated text content, use `CKEditor <http://ckeditor.com/>`_ by subclassing some of the builtin WTForms classes as follows::
from wtforms import TextAreaField
from wtforms.widgets import TextArea
class CKTextAreaWidget(TextArea):
def __call__(self, field, **kwargs):
if kwargs.get('class'):
kwargs['class'] += ' ckeditor'
else:
kwargs.setdefault('class', 'ckeditor')
return super(CKTextAreaWidget, self).__call__(field, **kwargs)
class CKTextAreaField(TextAreaField):
widget = CKTextAreaWidget()
class MessageAdmin(ModelView):
form_overrides = dict(body=wtf.FileField)
create_template = 'ckeditor.html'
edit_template = 'ckeditor.html'
For this to work, you would also need to create a template that extends the default
functionality by including the necessary CKEditor javascript on the `create` and
`edit` pages. Save this in `templates/ckeditor.html::
{% extends 'admin/model/edit.html' %}
{% block tail %}
{{ super() }}
<script src="http://cdnjs.cloudflare.com/ajax/libs/ckeditor/4.0.1/ckeditor.js"></script>
{% endblock %}
File & Image fields
*******************
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