Skip to main content

ModelAdmin

Trait ModelAdmin 

Source
pub trait ModelAdmin: AdminModel {
    // Provided methods
    fn list_display() -> &'static [&'static str] { ... }
    fn list_filter() -> &'static [&'static str] { ... }
    fn search_fields() -> &'static [&'static str] { ... }
    fn ordering() -> &'static [&'static str] { ... }
    fn list_per_page() -> usize { ... }
    fn readonly_fields() -> &'static [&'static str] { ... }
    fn fieldsets() -> &'static [Fieldset] { ... }
    fn bulk_actions() -> &'static [BulkAction] { ... }
}
Expand description

Django-style customisation surface for a registered admin model.

Every type that implements AdminModel gets a default impl via the blanket below. Override the methods you care about; everything else inherits sensible defaults.

Provided Methods§

Source

fn list_display() -> &'static [&'static str]

Columns shown on the list page, in order. Default: every field declared on AdminModel::FIELDS.

Returning &[] means “use the model’s full field list” — the list page expands the empty default into M::FIELDS. Any non-empty slice replaces the defaults verbatim.

Source

fn list_filter() -> &'static [&'static str]

Columns offered as filter chips in the sidebar. Default: none.

Source

fn search_fields() -> &'static [&'static str]

Columns searched by the list-page search box (case-insensitive substring match). Default: none.

Source

fn ordering() -> &'static [&'static str]

Default ordering. -foo for foo DESC, foo for foo ASC. Multiple entries → multi-column ORDER BY in slice order. Default: ["-id"] (newest first).

Source

fn list_per_page() -> usize

Rows per page on the list view. Default: 50.

Source

fn readonly_fields() -> &'static [&'static str]

Read-only fields on the change form. Default: none.

Source

fn fieldsets() -> &'static [Fieldset]

Field grouping on the change form. Default: empty — fall back to the framework heuristic (Default / System / Advanced).

Source

fn bulk_actions() -> &'static [BulkAction]

Custom bulk actions surfaced as extra buttons in the list-view bulk bar (next to the framework’s built-in Delete). Default: none.

BulkAction is metadata only — the dispatcher (AdminOps::execute_bulk_action) is what actually runs the action on the selected rows. Project models that need a custom action override AdminOps::execute_bulk_action to match on name and apply the work; the framework’s default impl returns a clear BadRequest for any name it doesn’t recognise, so a forgotten implementation surfaces as an error page rather than a silent no-op.

Dyn Compatibility§

This trait is not dyn compatible.

In older versions of Rust, dyn compatibility was called "object safety", so this trait is not object safe.

Implementors§