8.2.10.4.1.2. ModelView

class ModelView(model, session, name=None, category=None, endpoint=None, url=None, static_folder=None, menu_class_name=None, menu_icon_type=None, menu_icon_value=None)[source]

Methods

__delattr__

Implement delattr(self, name).

__dir__

Default dir() implementation.

__eq__

Return self==value.

__format__

Default object formatter.

__ge__

Return self>=value.

__getattribute__

Return getattr(self, name).

__getstate__

Helper for pickle.

__gt__

Return self>value.

__hash__

Return hash(self).

__init__

Constructor.

__init_subclass__

This method is called when a class is subclassed.

__le__

Return self<=value.

__lt__

Return self<value.

__ne__

Return self!=value.

__new__

__reduce__

Helper for pickle.

__reduce_ex__

Helper for pickle.

__repr__

Return repr(self).

__setattr__

Implement setattr(self, name, value).

__sizeof__

Size of object in memory, in bytes.

__str__

Return str(self).

__subclasshook__

Abstract classes can override this to customize issubclass().

_apply_filters

_apply_pagination

_apply_path_joins

Apply join path to the query.

_apply_search

Apply search to a query.

_apply_sorting

_create_ajax_loader

Model backend will override this to implement AJAX model loading.

_export_csv

Export a CSV of records as a stream.

_export_data

_export_tablib

Exports a variety of formats using the tablib library.

_get_column_by_idx

Return column index by

_get_default_order

Return default sort order

_get_endpoint

Generate Flask endpoint name.

_get_field_value

Get unformatted field value from the model

_get_filter_groups

Returns non-lazy version of filter strings

_get_filters

Get active filters as dictionary of URL arguments and values

_get_list_extra_args

Return arguments from query string.

_get_list_filter_args

_get_list_url

Generate page URL with current page, sort column and other parameters.

_get_list_value

Returns the value to be displayed.

_get_model_iterator

Return property iterator for the model

_get_ruleset_missing_fields

_get_view_url

Generate URL for the view.

_handle_view

Override builtin _handle_view in order to redirect users when a view is not accessible.

_on_model_change

Compatibility helper.

_order_by

Apply order_by to the query

_prettify_class_name

Split words in PascalCase string into separate words.

_prettify_name

Prettify pythonic variable name.

_process_ajax_references

Process form_ajax_refs and generate model loaders that will be used by the ajax_lookup view.

_refresh_cache

Refresh various cached variables.

_refresh_filters_cache

_refresh_form_rules_cache

_refresh_forms_cache

_remove_fields_from_form_class

_remove_fields_from_form_instance

_run_view

This method will run actual view function.

_show_missing_fields_warning

_validate_form_class

_validate_form_instance

action_delete

action_form

Instantiate model action form and return it.

action_view

Mass-model action view.

after_model_change

Perform some actions after a model was created or updated and committed to the database.

after_model_delete

Perform some actions after a model was deleted and committed to the database.

ajax_lookup

ajax_update

Edits a single column of a record in list view.

build_new_instance

Build new instance of a model.

create_blueprint

Create Flask blueprint.

create_form

Instantiate model creation form and return it.

create_model

Create model from form.

create_view

Create model view

delete_form

Instantiate model delete form and return it.

delete_model

Delete model.

delete_view

Delete model view.

details_view

Details model view

edit_form

Instantiate model editing form and return it.

edit_view

Edit model view

export

get_action_form

Create form class for a model action.

get_actions_list

Return a list and a dictionary of allowed actions.

get_column_name

Return a human-readable column name.

get_column_names

Returns a list of tuples with the model field name and formatted field name.

get_count_query

Return a the count query for the model type

get_create_form

Create form class for model creation view.

get_delete_form

Create form class for model delete view.

get_detail_value

Returns the value to be displayed in the detail view

get_details_columns

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.

get_edit_form

Create form class for model editing view.

get_empty_list_message

get_export_columns

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.

get_export_name

get_export_value

Returns the value to be displayed in export.

get_filter_arg

Given a filter flt, return a unique name for that filter in this view.

get_filters

Return a list of filter objects.

get_form

Get form class.

get_invalid_value_msg

Returns message, which should be printed in case of failed validation.

get_list

Return records from the database.

get_list_columns

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.

get_list_form

Get form class for the editable list view.

get_list_row_actions

Return list of row action objects, each is instance of BaseListRowAction

get_list_value

Returns the value to be displayed in the list view

get_one

Return a single model by its id.

get_pk_value

Return the primary key value from a model object.

get_query

Return a query for the model type.

get_save_return_url

Return url where user is redirected after successful form save.

get_sortable_columns

Returns a dictionary of the sortable columns.

get_url

Generate URL for the endpoint.

handle_action

Handle action request.

handle_filter

Postprocess (add joins, etc) for a filter.

handle_view_exception

inaccessible_callback

Handle the response to inaccessible views.

index_view

List view

init_actions

Initialize list of actions for the current administrative view.

init_search

Initialize search.

is_accessible

Override this method to add permission checks.

is_action_allowed

Override this method to allow or disallow actions based on some condition.

is_editable

Verify if column is editable.

is_sortable

Verify if column is sortable.

is_valid_filter

Verify that the provided filter object is valid.

is_visible

Override this method if you want dynamically hide or show administrative views from Flask-Admin menu structure

list_form

Instantiate model editing form for list view and return it.

on_form_prefill

Perform additional actions to pre-fill the edit form.

on_model_change

Perform some actions before a model is created or updated.

on_model_delete

Perform some actions before a model is deleted.

render

Render template

scaffold_auto_joins

Return a list of joined tables by going through the displayed columns.

scaffold_filters

Return list of enabled filters

scaffold_form

Create form from the model.

scaffold_inline_form_models

Contribute inline models to the form

scaffold_list_columns

Return a list of columns from the model.

scaffold_list_form

Create form for the index_view using only the columns from self.column_editable_list.

scaffold_pk

Return the primary key name(s) from a model If model has single primary key, will return a string and tuple otherwise

scaffold_sortable_columns

Return a dictionary of sortable columns.

search_placeholder

Return search placeholder.

update_model

Update model from form.

validate_form

Validate the form on submit.

__init__(model, session, name=None, category=None, endpoint=None, url=None, static_folder=None, menu_class_name=None, menu_icon_type=None, menu_icon_value=None)[source]

Constructor.

Parameters:
  • model – Model class

  • session – SQLAlchemy session

  • name – View name. If not set, defaults to the model name

  • category – Category name

  • endpoint – Endpoint name. If not set, defaults to the model name

  • url – Base URL. If not set, defaults to ‘/admin/’ + endpoint

  • 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

Attributes

__annotations__

__dict__

__doc__

__module__

__weakref__

list of weak references to the object

_debug

_default_view

_template_args

Extra template arguments.

_urls

action_disallowed_list

Set of disallowed action names.

can_create

Is model creation allowed

can_delete

Is model deletion allowed

can_edit

Is model editing allowed

can_export

Is model list export allowed

can_set_page_size

Allows to select page size via dropdown list

can_view_details

Setting this to true will enable the details view.

column_auto_select_related

Enable automatic detection of displayed foreign keys in this view and perform automatic joined loading for related models to improve query performance.

column_choices

Map choices to columns in list view

column_default_sort

Default sort column if no sorting is applied.

column_descriptions

Dictionary where key is column name and value is description for list view column or add/edit form field.

column_details_exclude_list

Collection of fields excluded from the details view.

column_details_list

Collection of the field names included in the details view.

column_display_actions

Controls the display of the row actions (edit, delete, details, etc.) column in the list view.

column_display_all_relations

Controls if list view should display all relations, not only many-to-one.

column_display_pk

Controls if the primary key should be displayed in the list view.

column_editable_list

Collection of the columns which can be edited from the list view.

column_exclude_list

Collection of excluded list column names.

column_export_exclude_list

Collection of fields excluded from the export.

column_export_list

Collection of the field names included in the export.

column_extra_row_actions

List of row actions (instances of BaseListRowAction).

column_filters

Collection of the column filters.

column_formatters

Dictionary of list view column formatters.

column_formatters_detail

Dictionary of list view column formatters to be used for the detail view.

column_formatters_export

Dictionary of list view column formatters to be used for export.

column_hide_backrefs

column_labels

Dictionary where key is column name and value is string to display.

column_list

column_searchable_list

Collection of the searchable columns.

column_select_related_list

List of parameters for SQLAlchemy subqueryload.

column_sortable_list

Collection of the sortable columns for the list view.

column_type_formatters

Dictionary of value type formatters to be used in the list view.

column_type_formatters_detail

Dictionary of value type formatters to be used in the detail view.

column_type_formatters_export

Dictionary of value type formatters to be used in the export.

create_modal

Setting this to true will display the create_view as a modal dialog.

create_modal_template

Default create modal template

create_template

Default create template

details_modal

Setting this to true will display the details_view as a modal dialog.

details_modal_template

Default details modal view template

details_template

Default details view template

edit_modal

Setting this to true will display the edit_view as a modal dialog.

edit_modal_template

Default edit modal template

edit_template

Default edit template

export_max_rows

Maximum number of rows allowed for export.

export_types

A list of available export filetypes.

fast_mass_delete

If set to False and user deletes more than one model using built in action, all models will be read from the database and then deleted one by one giving SQLAlchemy a chance to manually cleanup any dependencies (many-to-many relationships, etc).

filter_converter

Field to filter converter.

form

Form class.

form_ajax_refs

Use AJAX for foreign key model loading.

form_args

Dictionary of form field arguments.

form_choices

Map choices to form fields

form_columns

Collection of the model field names for the form.

form_create_rules

Customized rules for the create form.

form_edit_rules

Customized rules for the edit form.

form_excluded_columns

Collection of excluded form field names.

form_extra_fields

Dictionary of additional fields.

form_optional_types

List of field types that should be optional if column is not nullable.

form_overrides

Dictionary of form column overrides.

form_rules

List of rendering rules for model creation form.

form_widget_args

Dictionary of form widget rendering arguments.

ignore_hidden

Ignore field that starts with "_"

inline_models

Inline related-model editing for models with parent-child relations.

list_template

Default list view template

named_filter_urls

Set to True to use human-readable names for filters in URL parameters.

page_size

Default page size for pagination.

simple_list_pager

Enable or disable simple list pager.

column_display_pk = True

Controls if the primary key should be displayed in the list view.

column_hide_backrefs = False
form_base_class

alias of SecureForm

property column_list
is_accessible()[source]

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.

_handle_view(name, **kwargs)[source]

Override builtin _handle_view in order to redirect users when a view is not accessible.

__annotations__ = {}
__doc__ = None
__module__ = 'schedula.utils.form.server.admin'
_default_view = 'index_view'
_urls = [('/action/', 'action_view', ('POST',)), ('/ajax/lookup/', 'ajax_lookup', ('GET',)), ('/ajax/update/', 'ajax_update', ('POST',)), ('/new/', 'create_view', ('GET', 'POST')), ('/delete/', 'delete_view', ('POST',)), ('/details/', 'details_view', ('GET',)), ('/edit/', 'edit_view', ('GET', 'POST')), ('/export/<export_type>/', 'export', ('GET',)), ('/', 'index_view', ('GET',))]
action_view()

Mass-model action view.

ajax_lookup()
ajax_update()

Edits a single column of a record in list view.

create_view()

Create model view

delete_view()

Delete model view. Only POST method is allowed.

details_view()

Details model view

edit_view()

Edit model view

export(export_type)
index_view()

List view