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).
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_joinsApply join path to the query.
_apply_searchApply search to a query.
_apply_sorting_create_ajax_loaderModel backend will override this to implement AJAX model loading.
_export_csvExport a CSV of records as a stream.
_export_data_export_tablibExports a variety of formats using the tablib library.
_get_column_by_idxReturn column index by
_get_default_orderReturn default sort order
_get_endpointGenerate Flask endpoint name.
_get_field_valueGet unformatted field value from the model
_get_filter_groupsReturns non-lazy version of filter strings
_get_filtersGet active filters as dictionary of URL arguments and values
_get_list_extra_argsReturn arguments from query string.
_get_list_filter_args_get_list_urlGenerate page URL with current page, sort column and other parameters.
_get_list_valueReturns the value to be displayed.
_get_model_iteratorReturn property iterator for the model
_get_ruleset_missing_fields_get_view_urlGenerate URL for the view.
Override builtin _handle_view in order to redirect users when a view is not accessible.
_on_model_changeCompatibility helper.
_order_byApply order_by to the query
_prettify_class_nameSplit words in PascalCase string into separate words.
_prettify_namePrettify pythonic variable name.
_process_ajax_referencesProcess form_ajax_refs and generate model loaders that will be used by the ajax_lookup view.
_refresh_cacheRefresh various cached variables.
_refresh_filters_cache_refresh_form_rules_cache_refresh_forms_cache_remove_fields_from_form_class_remove_fields_from_form_instance_run_viewThis method will run actual view function.
_show_missing_fields_warning_validate_form_class_validate_form_instanceaction_deleteaction_formInstantiate model action form and return it.
Mass-model action view.
after_model_changePerform some actions after a model was created or updated and committed to the database.
after_model_deletePerform some actions after a model was deleted and committed to the database.
Edits a single column of a record in list view.
build_new_instanceBuild new instance of a model.
create_blueprintCreate Flask blueprint.
create_formInstantiate model creation form and return it.
create_modelCreate model from form.
Create model view
delete_formInstantiate model delete form and return it.
delete_modelDelete model.
Delete model view.
Details model view
edit_formInstantiate model editing form and return it.
Edit model view
get_action_formCreate form class for a model action.
get_actions_listReturn a list and a dictionary of allowed actions.
get_column_nameReturn a human-readable column name.
get_column_namesReturns a list of tuples with the model field name and formatted field name.
get_count_queryReturn a the count query for the model type
get_create_formCreate form class for model creation view.
get_delete_formCreate form class for model delete view.
get_detail_valueReturns the value to be displayed in the detail view
get_details_columnsUses 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_formCreate form class for model editing view.
get_empty_list_messageget_export_columnsUses 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_nameget_export_valueReturns the value to be displayed in export.
get_filter_argGiven a filter flt, return a unique name for that filter in this view.
get_filtersReturn a list of filter objects.
get_formGet form class.
get_invalid_value_msgReturns message, which should be printed in case of failed validation.
get_listReturn records from the database.
get_list_columnsUses 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_formGet form class for the editable list view.
get_list_row_actionsReturn list of row action objects, each is instance of
BaseListRowActionget_list_valueReturns the value to be displayed in the list view
get_oneReturn a single model by its id.
get_pk_valueReturn the primary key value from a model object.
get_queryReturn a query for the model type.
get_save_return_urlReturn url where user is redirected after successful form save.
get_sortable_columnsReturns a dictionary of the sortable columns.
get_urlGenerate URL for the endpoint.
handle_actionHandle action request.
handle_filterPostprocess (add joins, etc) for a filter.
handle_view_exceptioninaccessible_callbackHandle the response to inaccessible views.
List view
init_actionsInitialize list of actions for the current administrative view.
init_searchInitialize search.
Override this method to add permission checks.
is_action_allowedOverride this method to allow or disallow actions based on some condition.
is_editableVerify if column is editable.
is_sortableVerify if column is sortable.
is_valid_filterVerify that the provided filter object is valid.
is_visibleOverride this method if you want dynamically hide or show administrative views from Flask-Admin menu structure
list_formInstantiate model editing form for list view and return it.
on_form_prefillPerform additional actions to pre-fill the edit form.
on_model_changePerform some actions before a model is created or updated.
on_model_deletePerform some actions before a model is deleted.
renderRender template
scaffold_auto_joinsReturn a list of joined tables by going through the displayed columns.
scaffold_filtersReturn list of enabled filters
scaffold_formCreate form from the model.
scaffold_inline_form_modelsContribute inline models to the form
scaffold_list_columnsReturn a list of columns from the model.
scaffold_list_formCreate form for the index_view using only the columns from self.column_editable_list.
scaffold_pkReturn the primary key name(s) from a model If model has single primary key, will return a string and tuple otherwise
scaffold_sortable_columnsReturn a dictionary of sortable columns.
search_placeholderReturn search placeholder.
update_modelUpdate model from form.
validate_formValidate 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
__dict____weakref__list of weak references to the object
_debug_template_argsExtra template arguments.
action_disallowed_listSet of disallowed action names.
can_createIs model creation allowed
can_deleteIs model deletion allowed
can_editIs model editing allowed
can_exportIs model list export allowed
can_set_page_sizeAllows to select page size via dropdown list
can_view_detailsSetting this to true will enable the details view.
column_auto_select_relatedEnable automatic detection of displayed foreign keys in this view and perform automatic joined loading for related models to improve query performance.
column_choicesMap choices to columns in list view
column_default_sortDefault sort column if no sorting is applied.
column_descriptionsDictionary where key is column name and value is description for list view column or add/edit form field.
column_details_exclude_listCollection of fields excluded from the details view.
column_details_listCollection of the field names included in the details view.
column_display_actionsControls the display of the row actions (edit, delete, details, etc.) column in the list view.
column_display_all_relationsControls if list view should display all relations, not only many-to-one.
Controls if the primary key should be displayed in the list view.
column_editable_listCollection of the columns which can be edited from the list view.
column_exclude_listCollection of excluded list column names.
column_export_exclude_listCollection of fields excluded from the export.
column_export_listCollection of the field names included in the export.
column_extra_row_actionsList of row actions (instances of
BaseListRowAction).column_filtersCollection of the column filters.
column_formattersDictionary of list view column formatters.
column_formatters_detailDictionary of list view column formatters to be used for the detail view.
column_formatters_exportDictionary of list view column formatters to be used for export.
column_labelsDictionary where key is column name and value is string to display.
column_searchable_listCollection of the searchable columns.
column_select_related_listList of parameters for SQLAlchemy subqueryload.
column_sortable_listCollection of the sortable columns for the list view.
column_type_formattersDictionary of value type formatters to be used in the list view.
column_type_formatters_detailDictionary of value type formatters to be used in the detail view.
column_type_formatters_exportDictionary of value type formatters to be used in the export.
create_modalSetting this to true will display the create_view as a modal dialog.
create_modal_templateDefault create modal template
create_templateDefault create template
details_modalSetting this to true will display the details_view as a modal dialog.
details_modal_templateDefault details modal view template
details_templateDefault details view template
edit_modalSetting this to true will display the edit_view as a modal dialog.
edit_modal_templateDefault edit modal template
edit_templateDefault edit template
export_max_rowsMaximum number of rows allowed for export.
export_typesA list of available export filetypes.
fast_mass_deleteIf 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_converterField to filter converter.
formForm class.
form_ajax_refsUse AJAX for foreign key model loading.
form_argsDictionary of form field arguments.
form_choicesMap choices to form fields
form_columnsCollection of the model field names for the form.
form_create_rulesCustomized rules for the create form.
form_edit_rulesCustomized rules for the edit form.
form_excluded_columnsCollection of excluded form field names.
form_extra_fieldsDictionary of additional fields.
form_optional_typesList of field types that should be optional if column is not nullable.
form_overridesDictionary of form column overrides.
form_rulesList of rendering rules for model creation form.
form_widget_argsDictionary of form widget rendering arguments.
ignore_hiddenIgnore field that starts with "_"
inline_modelsInline related-model editing for models with parent-child relations.
list_templateDefault list view template
named_filter_urlsSet to True to use human-readable names for filters in URL parameters.
page_sizeDefault page size for pagination.
simple_list_pagerEnable 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