flask_admin.contrib.mongoengine¶
MongoEngine model backend implementation.
- class ModelView(model: type[mongoengine.Document], name: str | None = None, category: str | None = None, endpoint: str | None = None, url: str | None = None, static_folder: str | None = None, menu_class_name: str | None = None, menu_icon_type: str | None = None, menu_icon_value: str | None = None)[source]¶
MongoEngine model scaffolding.
Constructor
- Parameters:
model – Model class
name – Display name
category – Display category
endpoint – Endpoint
url – Custom URL
menu_class_name – Optional class name for the menu item.
menu_icon_type –
Optional icon. Possible icon types:
flask_admin.consts.ICON_TYPE_GLYPH - Bootstrap glyph icon
flask_admin.consts.ICON_TYPE_FONT_AWESOME - Font Awesome icon
- flask_admin.consts.ICON_TYPE_IMAGE - Image relative to
Flask static directory
flask_admin.consts.ICON_TYPE_IMAGE_URL - Image with full URL
menu_icon_value –
Icon glyph name or URL, depending on menu_icon_type setting
Class inherits configuration options from
BaseModelViewand they’re not displayed here.
- column_filters: Collection[str | BaseMongoEngineFilter] | None = None¶
Collection of column filters used in the list view.
Can contain either: - Field names (str): allow any appropriate filter operation based on the field’s data type. - Instances of
BaseFilterclasses: restrict or customize which filters are available for a specific field.Filters will be grouped by name when displayed in the drop-down.
For example:
class MyModelView(BaseModelView): column_filters = ('user', 'email')
or:
from flask_admin.contrib.mongoengine.filters import BooleanEqualFilter class MyModelView(BaseModelView): column_filters = (BooleanEqualFilter(column=User.name, name='Name'),)
or:
from flask_admin.contrib.mongoengine.filters import BaseMongoEngineFilter class FilterLastNameBrown(BaseMongoEngineFilter): def apply(self, query: QuerySet, value: t.Any) -> QuerySet: if value == '1': return query.filter(self.column == "Brown") else: return query.filter(self.column != "Brown") def operation(self): return 'is Brown' class MyModelView(BaseModelView): column_filters = [ FilterLastNameBrown( column=User.last_name, name='Last Name', options=(('1', 'Yes'), ('0', 'No')) ) ]
- action_disallowed_list: t.Sequence[str]¶
Set of disallowed action names. For example, if you want to disable mass model deletion, do something like this:
- class MyModelView(BaseModelView):
action_disallowed_list = [‘delete’]
- action_form(obj: type | None = None) Form¶
Instantiate model action form and return it.
Override to implement custom behavior.
- action_view() Response | Response¶
Mass-model action view.
- after_model_change(form: Form, model: Any, is_created: bool) None¶
Perform some actions after a model was created or updated and committed to the database.
Called from create_model after successful database commit.
By default does nothing.
- Parameters:
form – Form used to create/update model
model – Model that was created/updated
is_created – True if model was created, False if model was updated
- after_model_delete(model: Any) None¶
Perform some actions after a model was deleted and committed to the database.
Called from delete_model after successful database commit (if it has any meaning for a store backend).
By default does nothing.
- Parameters:
model – Model that was deleted
- ajax_update() None | tuple[str, int] | str¶
Edits a single column of a record in list view. Usually used with column_editable_list that integrates with the x-editable library.
// you can use jQuery to make ajax calls like this: $.ajax({ url: '/admin/<your_model_view_endpoint>/ajax/update/', type: 'POST', data: { "list_form_pk" : "<primary_key_value>", "<column_name>": "<new_value>" }, success: function(response) { // handle success }, error: function(response) { // handle error } });
- allowed_search_types = (<class 'mongoengine.fields.StringField'>, <class 'mongoengine.fields.URLField'>, <class 'mongoengine.fields.EmailField'>, <class 'mongoengine.fields.ReferenceField'>)¶
List of allowed search field types.
- can_view_details: bool = False¶
Setting this to true will enable the details view. This is recommended when there are too many columns to display in the list_view.
- column_choices: dict[str, t.Sequence[tuple[str, str]]] | None = None¶
Map choices to columns in list view
Example:
class MyModelView(BaseModelView): column_choices = { 'my_column': [ ('db_value', 'display_value'), ] }
- column_default_sort: None | str | tuple[str, bool] | list[tuple[str, bool]] = None¶
Default sort column if no sorting is applied.
Example:
class MyModelView(BaseModelView): column_default_sort = 'user'
You can use tuple to control ascending descending order. In following example, items will be sorted in descending order:
class MyModelView(BaseModelView): column_default_sort = ('user', True)
If you want to sort by more than one column, you can pass a list of tuples:
class MyModelView(BaseModelView): column_default_sort = [('name', True), ('last_name', True)]
- column_descriptions: dict[str, str] | None = None¶
Dictionary where key is column name and value is description for list view column or add/edit form field.
For example:
class MyModelView(BaseModelView): column_descriptions = dict( full_name='First and Last name' )
- column_details_exclude_list: list[str] | None = None¶
Collection of fields excluded from the details view.
- column_details_list: list[str] | None = None¶
Collection of the field names included in the details view. If set to None, will get them from the model.
- column_display_actions: bool = True¶
Controls the display of the row actions (edit, delete, details, etc.) column in the list view.
Useful for preventing a blank column from displaying if your view does not use any build-in or custom row actions.
This column is not hidden automatically due to backwards compatibility.
Note: This only affects display and does not control whether the row actions endpoints are accessible.
- column_editable_list: t.Collection[str] | None = None¶
Collection of the columns which can be edited from the list view.
For example:
class MyModelView(BaseModelView): column_editable_list = ('name', 'last_name')
- column_exclude_list: t.Sequence[str] | None¶
Collection of excluded list column names.
For example:
class MyModelView(BaseModelView): column_exclude_list = ('last_name', 'email')
- column_export_list: list[str] | None = None¶
Collection of the field names included in the export. If set to None, will get them from the model.
- column_extra_row_actions: list[BaseListRowAction] | None = None¶
List of row actions (instances of
BaseListRowAction).Flask-Admin will generate standard per-row actions (edit, delete, etc) and will append custom actions from this list right after them.
For example:
from flask_admin.model.template import EndpointLinkRowAction, LinkRowAction class MyModelView(BaseModelView): column_extra_row_actions = [ LinkRowAction( 'glyphicon glyphicon-off', 'http://direct.link/?id={row_id}' ), EndpointLinkRowAction( 'glyphicon glyphicon-test', 'my_view.index_view' ) ]
- column_formatters: T_COLUMN_FORMATTERS¶
Dictionary of list view column formatters.
For example, if you want to show price multiplied by two, you can do something like this:
class MyModelView(BaseModelView): column_formatters = dict(price=lambda v, c, m, p: m.price*2)
or using Jinja2 macro in template:
from flask_admin.model.template import macro class MyModelView(BaseModelView): column_formatters = dict(price=macro('render_price')) # in template {% macro render_price(model, column) %} {{ model.price * 2 }} {% endmacro %}
The Callback function has the prototype:
def formatter(view, context, model, name): # `view` is current administrative view # `context` is instance of jinja2.runtime.Context # `model` is model instance # `name` is property name pass
- column_formatters_detail: T_COLUMN_FORMATTERS | None = None¶
Dictionary of list view column formatters to be used for the detail view.
Defaults to column_formatters when set to None.
Functions the same way as column_formatters except that macros are not supported. that macros are not supported.
- column_formatters_export: T_COLUMN_FORMATTERS | None = None¶
Dictionary of list view column formatters to be used for export.
Defaults to column_formatters when set to None.
Functions the same way as column_formatters except that macros are not supported.
- column_labels: dict[str, str]¶
Dictionary where key is column name and value is string to display.
For example:
class MyModelView(BaseModelView): column_labels = dict(name='Name', last_name='Last Name')
- column_list: T_COLUMN_LIST | None¶
Collection of the model field names for the list view. If set to None, will get them from the model.
For example:
class MyModelView(BaseModelView): column_list = ('name', 'last_name', 'email')
(Added in 1.4.0) SQLAlchemy model attributes can be used instead of strings:
class MyModelView(BaseModelView): column_list = ('name', User.last_name)
- When using SQLAlchemy models, you can reference related columns like this::
- class MyModelView(BaseModelView):
column_list = (‘<relationship>.<related column name>’,)
- column_searchable_list: T_COLUMN_LIST | None¶
A collection of the searchable columns. It is assumed that only text-only fields are searchable, but it is up to the model implementation to decide.
Example:
class MyModelView(BaseModelView): column_searchable_list = ('name', 'email')
- column_sortable_list: T_COLUMN_LIST | None¶
Collection of the sortable columns for the list view. If set to None, will get them from the model.
For example:
class MyModelView(BaseModelView): column_sortable_list = ('name', 'last_name')
If you want to explicitly specify field/column to be used while sorting, you can use a tuple:
class MyModelView(BaseModelView): column_sortable_list = ('name', ('user', 'user.username'))
You can also specify multiple fields to be used while sorting:
class MyModelView(BaseModelView): column_sortable_list = ( 'name', ('user', ('user.first_name', 'user.last_name')))
When using SQLAlchemy models, model attributes can be used instead of strings:
class MyModelView(BaseModelView): column_sortable_list = ('name', ('user', User.username))
- column_type_formatters: dict[type, Callable[[flask_admin.model.BaseModelView, Any, str], str | Markup]] = {<class 'NoneType'>: <function empty_formatter>, <class 'bool'>: <function bool_formatter>, <class 'dict'>: <function dict_formatter>, <class 'list'>: <function list_formatter>, <class 'mongoengine.base.datastructures.BaseList'>: <function list_formatter>, <class 'mongoengine.fields.GridFSProxy'>: <function grid_formatter>, <class 'mongoengine.fields.ImageGridFsProxy'>: <function grid_image_formatter>, <enum 'Enum'>: <function enum_formatter>}¶
Customized type formatters for MongoEngine backend
- column_type_formatters_detail: T_COLUMN_TYPE_FORMATTERS | None = None¶
Dictionary of value type formatters to be used in the detail view.
By default, two types are formatted:
Nonewill be displayed as an empty stringlistwill be joined using ‘, ‘
Functions the same way as column_type_formatters.
- column_type_formatters_export: T_COLUMN_TYPE_FORMATTERS | None = None¶
Dictionary of value type formatters to be used in the export.
By default, two types are formatted:
Nonewill be displayed as an empty stringlistwill be joined using ‘, ‘
Functions the same way as column_type_formatters.
- create_form(obj: Any | None = None) Form¶
Instantiate model creation form and return it.
Override to implement custom behavior.
- create_model(form: Form) Document | bool[source]¶
Create model helper
- Parameters:
form – Form instance
- delete_form() BaseForm¶
Instantiate model delete form and return it.
Override to implement custom behavior.
The delete form originally used a GET request, so delete_form accepts both GET and POST request for backwards compatibility.
- delete_model(model: type[mongoengine.Document]) bool[source]¶
Delete model helper
- Parameters:
model – Model instance
- delete_view() Response | Response¶
Delete model view. Only POST method is allowed.
- details_modal_template: str = 'admin/model/modals/details.html'¶
Default details modal view template
- edit_form(obj: Any | None = None) Form¶
Instantiate model editing form and return it.
Override to implement custom behavior.
- export_max_rows: int = 0¶
Maximum number of rows allowed for export.
Unlimited by default. Uses page_size if set to None.
- export_types: t.Collection[str] = ['csv']¶
A list of available export filetypes. csv only is default, but any filetypes supported by tablib can be used.
Check tablib for https://tablib.readthedocs.io/en/stable/formats.html for supported types.
- filter_converter = <flask_admin.contrib.mongoengine.filters.FilterConverter object>¶
Field to filter converter.
Override this attribute to use a non-default converter.
- form: type[Form] | None = None¶
Form class. Override if you want to use custom form for your model. Will completely disable form scaffolding functionality.
For example:
class MyForm(Form): name = StringField('Name') class MyModelView(BaseModelView): form = MyForm
- form_ajax_refs: dict[str, AjaxModelLoader | dict[str, t.Any]] | None = None¶
Use AJAX for foreign key model loading.
Should contain dictionary, where key is field name and value is either a dictionary which configures AJAX lookups or backend-specific AjaxModelLoader class instance.
For example, it can look like:
class MyModelView(BaseModelView): form_ajax_refs = { 'user': { 'fields': ('first_name', 'last_name', 'email'), 'placeholder': 'Please select', 'page_size': 10, 'minimum_input_length': 0, } }
Or with SQLAlchemy backend like this:
class MyModelView(BaseModelView): form_ajax_refs = { 'user': QueryAjaxModelLoader( 'user', db.session, User, fields=['email'], page_size=10 ) }
If you need custom loading functionality, you can implement your custom loading behavior in your AjaxModelLoader class.
- form_args: dict[str, T_FIELD_ARGS_VALIDATORS_FILES] | None = None¶
Dictionary of form field arguments. Refer to WTForms documentation for list of possible options.
Example:
from wtforms.validators import DataRequired class MyModelView(BaseModelView): form_args = dict( name=dict(label='First Name', validators=[DataRequired()]) )
- form_columns: list[str] | None = None¶
Collection of the model field names for the form. If set to None will get them from the model.
Example:
class MyModelView(BaseModelView): form_columns = ('name', 'email')
(Added in 1.4.0) SQLAlchemy model attributes can be used instead of strings:
class MyModelView(BaseModelView): form_columns = ('name', User.last_name)
SQLA Note: Model attributes must be on the same model as your ModelView or you will need to use inline_models.
- form_create_rules: T_RULES_SEQUENCE | None = None¶
Customized rules for the create form. Override form_rules if present.
- form_edit_rules: T_RULES_SEQUENCE | None = None¶
Customized rules for the edit form. Override form_rules if present.
- form_excluded_columns: t.Collection[str]¶
Collection of excluded form field names.
For example:
class MyModelView(BaseModelView): form_excluded_columns = ('last_name', 'email')
- form_extra_fields: dict[str, Field] | None = None¶
Dictionary of additional fields.
Example:
class MyModelView(BaseModelView): form_extra_fields = { 'password': PasswordField('Password') }
You can control order of form fields using
form_columnsproperty. For example:class MyModelView(BaseModelView): form_columns = ('name', 'email', 'password', 'secret') form_extra_fields = { 'password': PasswordField('Password') }
In this case, password field will be put between email and secret fields that are autogenerated.
- form_overrides: dict[str, type[Field]] | None = None¶
Dictionary of form column overrides.
Example:
class MyModelView(BaseModelView): form_overrides = dict(name=wtf.FileField)
- form_rules: T_RULES_SEQUENCE | None = None¶
List of rendering rules for model creation form.
This property changed default form rendering behavior and makes possible to rearrange order of rendered fields, add some text between fields, group them, etc. If not set, will use default Flask-Admin form rendering logic.
Here’s simple example which illustrates how to use:
from flask_admin.form import rules class MyModelView(ModelView): form_rules = [ # Define field set with header text and four fields rules.FieldSet( ('first_name', 'last_name', 'email', 'phone'), 'User' ), # ... and it is just shortcut for: rules.Header('User'), rules.Field('first_name'), rules.Field('last_name'), # ... # It is possible to create custom rule blocks: MyBlock('Hello World'), # It is possible to call macros from current context rules.Macro('my_macro', foobar='baz') ]
- form_subdocuments: dict[Any, Any] | None = None¶
Subdocument configuration options.
This field accepts dictionary, where key is field name and value is either dictionary or instance of the flask_admin.contrib.mongoengine.EmbeddedForm.
Consider following example:
class Comment(db.EmbeddedDocument): name = db.StringField(max_length=20, required=True) value = db.StringField(max_length=20) class Post(db.Document): text = db.StringField(max_length=30) data = db.EmbeddedDocumentField(Comment) class MyAdmin(ModelView): form_subdocuments = { 'data': { 'form_columns': ('name',) } }
In this example, Post model has child Comment subdocument. When generating form for Comment embedded document, Flask-Admin will only create name field.
It is also possible to use class-based embedded document configuration:
class CommentEmbed(EmbeddedForm): form_columns = ('name',) class MyAdmin(ModelView): form_subdocuments = { 'data': CommentEmbed() }
Arbitrary depth nesting is supported:
class SomeEmbed(EmbeddedForm): form_excluded_columns = ('test',) class CommentEmbed(EmbeddedForm): form_columns = ('name',) form_subdocuments = { 'inner': SomeEmbed() } class MyAdmin(ModelView): form_subdocuments = { 'data': CommentEmbed() }
There’s also support for forms embedded into ListField. All you have to do is to create nested rule with None as a name. Even though it is slightly confusing, but that’s how Flask-MongoEngine creates form fields embedded into ListField:
class Comment(db.EmbeddedDocument): name = db.StringField(max_length=20, required=True) value = db.StringField(max_length=20) class Post(db.Document): text = db.StringField(max_length=30) data = db.ListField(db.EmbeddedDocumentField(Comment)) class MyAdmin(ModelView): form_subdocuments = { 'data': { 'form_subdocuments': { None: { 'form_columns': ('name',) } } } }
- form_widget_args: dict[str, dict[str, int | str | bool]] | None = None¶
Dictionary of form widget rendering arguments. Use this to customize how widget is rendered without using custom template.
Example:
class MyModelView(BaseModelView): form_widget_args = { 'description': { 'rows': 10, 'style': 'color: black' }, 'other_field': { 'disabled': True } }
Changing the format of a DateTimeField will require changes to both form_widget_args and form_args.
Example:
form_args = dict( # changes how the input is parsed by strptime (12 hour time) start=dict(format='%Y-%m-%d %I:%M %p') ) form_widget_args = dict( start={ 'data-date-format': u'yyyy-mm-dd HH:ii P', 'data-show-meridian': 'True' } # changes how the DateTimeField displays the time )
- get_action_form() type[BaseForm]¶
Create form class for a model action.
Override to implement customized behavior.
- get_actions_list() tuple[list[Any], dict[Any, Any]]¶
Return a list and a dictionary of allowed actions.
- get_column_name(field: str) str¶
Return a human-readable column name.
- Parameters:
field – Model field name.
- get_column_names(only_columns: T_COLUMN_LIST, excluded_columns: t.Sequence[str] | None) list[tuple[T_COLUMN, str]]¶
Returns a list of tuples with the model field name and formatted field name.
- Parameters:
only_columns – List of columns to include in the results. If not set, scaffold_list_columns will generate the list from the model.
excluded_columns – List of columns to exclude from the results if only_columns is not set.
- get_create_form() type[Form]¶
Create form class for model creation view.
Override to implement customized behavior.
- get_delete_form() type[BaseForm]¶
Create form class for model delete view.
Override to implement customized behavior.
- get_detail_value(context: Context, model: Any, name: str) Any¶
Returns the value to be displayed in the detail view
- Parameters:
context –
jinja2.runtime.Contextmodel – Model instance
name – Field name
- get_details_columns() list[tuple[T_COLUMN, str]]¶
Uses get_column_names to get a list of tuples with the model field name and formatted name for the columns in column_details_list and not in column_details_exclude_list. If column_details_list is not set, the columns from scaffold_list_columns will be used.
- get_edit_form() type[Form]¶
Create form class for model editing view.
Override to implement customized behavior.
- get_export_columns() list[tuple[T_COLUMN, str]]¶
Uses get_column_names to get a list of tuples with the model field name and formatted name for the columns in column_export_list and not in column_export_exclude_list. If column_export_list is not set, it will attempt to use the columns from column_list or finally the columns from scaffold_list_columns will be used.
- get_export_value(model: T_ORM_MODEL, name: T_COLUMN) t.Any¶
Returns the value to be displayed in export. Allows export to use different (non HTML) formatters.
- Parameters:
model – Model instance
name – Field name
- get_filter_arg(index: int, flt: BaseFilter) str¶
Given a filter flt, return a unique name for that filter in this view.
Does not include the flt[n]_ portion of the filter name.
- Parameters:
index – Filter index in _filters array
flt – Filter instance
- get_filters() list[BaseFilter] | None¶
Return a list of filter objects.
If your model backend implementation does not support filters, override this method and return None.
- get_form() type[Form]¶
Get form class.
If
self.formis set, will return it and will callself.scaffold_formotherwise.Override to implement customized behavior.
- get_invalid_value_msg(value: str, filter: BaseFilter) str¶
Returns message, which should be printed in case of failed validation. :param value: Invalid value :param filter: Filter :return: string
- get_list(page: int | None, sort_column: str, sort_desc: bool, search: str | None, filters: Sequence[tuple[int, str, str]] | None, execute: bool = True, page_size: int | None = None) tuple[int | None, Document][source]¶
Get list of objects from MongoEngine
- Parameters:
page – Page number
sort_column – Sort column
sort_desc – Sort descending
search – Search criteria
filters – List of applied filters
execute – Run query immediately or not
page_size – Number of results. Defaults to ModelView’s page_size. Can be overriden to change the page_size limit. Removing the page_size limit requires setting page_size to 0 or False.
- get_list_columns() list[tuple[T_COLUMN, str]]¶
Uses get_column_names to get a list of tuples with the model field name and formatted name for the columns in column_list and not in column_exclude_list. If column_list is not set, the columns from scaffold_list_columns will be used.
- get_list_form() type[Form]¶
Get form class for the editable list view.
Uses only validators from form_args to build the form class.
Allows overriding the editable list view field/widget. For example:
from flask_admin.model.widgets import XEditableWidget class CustomWidget(XEditableWidget): def get_kwargs(self, subfield, kwargs): if subfield.type == 'TextAreaField': kwargs['data-type'] = 'textarea' kwargs['data-rows'] = '20' # elif: kwargs for other fields return kwargs class MyModelView(BaseModelView): def get_list_form(self): return self.scaffold_list_form(widget=CustomWidget)
- get_list_row_actions() list[BaseListRowAction]¶
Return list of row action objects, each is instance of
BaseListRowAction
- get_list_value(context: Context, model: Any, name: str) Any¶
Returns the value to be displayed in the list view
- Parameters:
context –
jinja2.runtime.Contextmodel – Model instance
name – Field name
- get_one(id: Any) Any | None[source]¶
Return a single model instance by its ID
- Parameters:
id – Model ID
- get_pk_value(model: type[mongoengine.Document]) Any[source]¶
Return the primary key value from the model instance
- Parameters:
model – Model instance
- get_query() QuerySet[source]¶
Returns the QuerySet for this view. By default, it returns all the objects for the current model.
- get_save_return_url(model: Any, is_created: bool = False) str¶
Return url where user is redirected after successful form save.
- Parameters:
model – Saved object
is_created – Whether new object was created or existing one was updated
For example, redirect use to object details view after form save:
class MyModelView(ModelView): can_view_details = True def get_save_return_url(self, model, is_created): return self.get_url('.details_view', id=model.id)
- get_sortable_columns() dict[T_COLUMN, T_COLUMN]¶
Returns a dictionary of the sortable columns. Key is a model field name and value is sort column (for example - attribute).
If column_sortable_list is set, will use it. Otherwise, will call scaffold_sortable_columns to get them from the model.
- get_url(endpoint: str, **kwargs: Any) str¶
Generate URL for the endpoint. If you want to customize URL generation logic (persist some query string argument, for example), this is right place to do it.
- Parameters:
endpoint – Flask endpoint name
kwargs – Arguments for url_for
- handle_action(return_view: str | None = None) Response | Response¶
Handle action request.
- Parameters:
return_view – Name of the view to return to after the request. If not provided, will return user to the return url in the form or the list view.
- handle_filter(filter: BaseFilter) BaseFilter¶
Postprocess (add joins, etc) for a filter.
- Parameters:
filter – Filter object to postprocess
- inaccessible_callback(name: Any, **kwargs: Any) Response | str | bytes | list[Any] | Mapping[str, Any] | Iterator[str] | Iterator[bytes] | AsyncIterable[str] | AsyncIterable[bytes] | tuple[Response | str | bytes | list[Any] | Mapping[str, Any] | Iterator[str] | Iterator[bytes] | AsyncIterable[str] | AsyncIterable[bytes], Headers | Mapping[str, str | list[str] | tuple[str, ...]] | Sequence[tuple[str, str | list[str] | tuple[str, ...]]]] | tuple[Response | str | bytes | list[Any] | Mapping[str, Any] | Iterator[str] | Iterator[bytes] | AsyncIterable[str] | AsyncIterable[bytes], int] | tuple[Response | str | bytes | list[Any] | Mapping[str, Any] | Iterator[str] | Iterator[bytes] | AsyncIterable[str] | AsyncIterable[bytes], int, Headers | Mapping[str, str | list[str] | tuple[str, ...]] | Sequence[tuple[str, str | list[str] | tuple[str, ...]]]] | WSGIApplication¶
Handle the response to inaccessible views.
By default, it throw HTTP 403 error. Override this method to customize the behaviour.
- is_accessible() bool¶
Override this method to add permission checks.
Flask-Admin does not make any assumptions about the authentication system used in your application, so it is up to you to implement it.
By default, it will allow access for everyone.
- is_action_allowed(name: str) bool[source]¶
Override this method to allow or disallow actions based on some condition.
The default implementation only checks if the particular action is not in action_disallowed_list.
- is_sortable(name: str) bool¶
Verify if column is sortable.
Not case-sensitive.
- Parameters:
name – Column name.
- is_valid_filter(filter: BaseMongoEngineFilter) bool[source]¶
Validate if the provided filter is a valid MongoEngine filter
- Parameters:
filter – Filter object
- is_visible() bool¶
Override this method if you want dynamically hide or show administrative views from Flask-Admin menu structure
By default, item is visible in menu.
Please note that item should be both visible and accessible to be displayed in menu.
- list_form(obj: object | None = None) Form¶
Instantiate model editing form for list view and return it.
Override to implement custom behavior.
- model_form_converter¶
alias of
CustomModelConverter
- named_filter_urls: bool = False¶
Set to True to use human-readable names for filters in URL parameters.
False by default so as to be robust across translations.
Changing this parameter will break any existing URLs that have filters.
- object_id_converter¶
alias of
ObjectId
- on_form_prefill(form: Form, id: Any) None¶
Perform additional actions to pre-fill the edit form.
Called from edit_view, if the current action is rendering the form rather than receiving client side input, after default pre-filling has been performed.
By default does nothing.
You only need to override this if you have added custom fields that depend on the database contents in a way that Flask-admin can’t figure out by itself. Fields that were added by name of a normal column or relationship should work out of the box.
- Parameters:
form – Form instance
id – id of the object that is going to be edited
- on_model_change(form: Form, model: Any, is_created: bool) None¶
Perform some actions before a model is created or updated.
Called from create_model and update_model in the same transaction (if it has any meaning for a store backend).
By default does nothing.
- Parameters:
form – Form used to create/update model
model – Model that will be created/updated
is_created – Will be set to True if model was created and to False if edited
- on_model_delete(model: Any) None¶
Perform some actions before a model is deleted.
Called from delete_model in the same transaction (if it has any meaning for a store backend).
By default do nothing.
- page_size_options: tuple[int, ...] = (20, 50, 100)¶
Sets the page size options available, if can_set_page_size is True
- render(template: str, **kwargs: Any) str¶
Render template
- Parameters:
template – Template path to render
kwargs – Template arguments
- scaffold_filters(name: str) Any[source]¶
Return filter object(s) for the field
- Parameters:
name – Either field name or field instance
- scaffold_list_form(widget: type[Input | flask_admin.model.widgets.InlineFieldListWidget | flask_admin.model.widgets.InlineFormWidget | flask_admin.model.widgets.AjaxSelect2Widget | flask_admin.model.widgets.XEditableWidget | WidgetProtocol] | None = None, validators: dict[str, T_FIELD_ARGS_VALIDATORS_FILES] | None = None) type[BaseListForm][source]¶
Create form for the index_view using only the columns from self.column_editable_list.
- Parameters:
widget – WTForms widget class. Defaults to XEditableWidget.
validators – form_args dict with only validators {‘name’: {‘validators’: [required()]}}
- scaffold_sortable_columns() dict[str, Any][source]¶
Return a dictionary of sortable columns (name, field)
- simple_list_pager: bool = False¶
Enable or disable simple list pager. If enabled, model interface would not run count query and will only show prev/next pager buttons.