admin

Module: espressodb.base.admin

BaseAdmin(model, admin_site)

Extension to regular admin.ModelAdmin which stores user as request logged in user on default.

ListViewAdmin(model, admin_site, **kwargs)

List view admin which displays all model fields.

register_admins(app_name[, exclude_models, …])

Tries to load all models from this app and registers ListViewAdmin sites.


Helper classes for setting up an admin page on start

class BaseAdmin(model, admin_site)[source]

Extension to regular admin.ModelAdmin which stores user as request logged in user on default.

save_model(request, obj, form, change)[source]

Overwrites obj.user with request.user before actual save.

class ListViewAdmin(model, admin_site, **kwargs)[source]

List view admin which displays all model fields.

search_fields

The fields which are searchable on the admin page. Does only render fields which are present in list_display

list_display

The fields to display as a column on the admin page. Defaults to ["id", "instance_name", ..., "tag"] where ... are the model default fields.

The fields which will be a link to the detail view. Defaults to ["instance_name"] or ["id"] or the first field in list_display (if the previous option are not present in list_display).

\*\*kwargs

Kwargs for the parent init.

__init__(model, admin_site, **kwargs)[source]

Sets the list display fields to espressodb defaults and model custom fields.

static instance_name(obj)[source]

Returns the name of the instance

Parameters

obj (Base) – The model instance to render.

Return type

str

register_admins(app_name, exclude_models=None, admin_class=None)[source]

Tries to load all models from this app and registers ListViewAdmin sites.

Parameters
  • app_name (str) – The name of the app.

  • exclude_models (Optional[List[str]]) – Models contained in this app which should not appear on the admin page. Uses the class name of the model.

  • admin_class (Optional[ModelAdmin]) – The admin model used to render the admin page. Defaults to ListViewAdmin.

Calls admin.site.register() for all models within the specified app.