flask.ext.admin.contrib.pymongo

PyMongo model backend implementation.

class ModelView(coll, name=None, category=None, endpoint=None, url=None)

MongoEngine model scaffolding.

Class inherits configuration options from BaseModelView and they’re not displayed here.
column_filters = None

Collection of the column filters.

Should contain instances of flask.ext.admin.contrib.pymongo.filters.BasePyMongoFilter classes.

For example:

class MyModelView(BaseModelView):
    column_filters = (BooleanEqualFilter(User.name, 'Name'),)
action_view(*args, **kwargs)

Mass-model action view.

after_model_change(form, model, is_created)

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
create_blueprint(admin)

Create Flask blueprint.

create_form(obj=None)

Instantiate model creation form and return it.

Override to implement custom behavior.

create_model(form)

Create model helper

Parameters:form – Form instance
create_view(*args, **kwargs)

Create model view

delete_model(model)

Delete model helper

Parameters:model – Model instance
delete_view(*args, **kwargs)

Delete model view. Only POST method is allowed.

edit_form(obj)

Create edit form from the MongoDB document

edit_view(*args, **kwargs)

Edit model view

get_actions_list()

Return a list and a dictionary of allowed actions.

get_column_name(field)

Return a human-readable column name.

Parameters:field – Model field name.
get_create_form()

Create form class for model creation view.

Override to implement customized behavior.

get_edit_form()

Create form class for model editing view.

Override to implement customized behavior.

get_filter_arg(index, flt)

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()

Return a list of filter objects.

If your model backend implementation does not support filters, override this method and return None.

get_form()

Get form class.

If self.form is set, will return it and will call self.scaffold_form otherwise.

Override to implement customized behavior.

get_list(page, sort_column, sort_desc, search, filters, execute=True)

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 fiters
  • execute – Run query immediately or not
get_list_columns()

Returns a list of the model field names. If column_list was set, returns it. Otherwise calls scaffold_list_columns to generate the list from the model.

get_list_value(context, model, name)

Returns the value to be displayed in the list view

Parameters:
  • contextjinja2.runtime.Context
  • model – Model instance
  • name – Field name
get_one(id)

Return single model instance by ID

Parameters:id – Model ID
get_pk_value(model)

Return primary key value from the model instance

Parameters:model – Model instance
get_sortable_columns()

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.

handle_action(return_view=None)

Handle action request.

Parameters:return_view – Name of the view to return to after the request. If not provided, will return user to the index view.
index_view(*args, **kwargs)

List view

init_actions()

Initialize list of actions for the current administrative view.

Init search

is_accessible()

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_sortable(name)

Verify if column is sortable.

Parameters:name – Column name.
is_valid_filter(filter)

Validate if it is valid MongoEngine filter

Parameters:filter – Filter object
is_visible()

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.

on_model_change(form, model, is_created)

Perform some actions after 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)

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.

render(template, **kwargs)

Render template

Parameters:
  • template – Template path to render
  • kwargs – Template arguments
scaffold_filters(attr)

Return filter object(s) for the field

Parameters:name – Either field name or field instance
scaffold_list_columns()

Scaffold list columns

scaffold_sortable_columns()

Return sortable columns dictionary (name, field)

update_model(form, model)

Update model helper

Parameters:
  • form – Form instance
  • model – Model instance to update

Related Topics

This Page