Skip to main content

AdminModel

Trait AdminModel 

Source
pub trait AdminModel:
    Send
    + Sync
    + 'static {
Show 14 methods // Required methods fn slug(&self) -> &'static str; fn display_name(&self) -> &'static str; fn display_name_plural(&self) -> &'static str; fn fields(&self) -> Vec<AdminField>; fn list( &self, pool: &Pool<AsyncPgConnection>, params: ListParams, ) -> Pin<Box<dyn Future<Output = Result<ListResult, AdminError>> + Send + '_>>; fn get( &self, pool: &Pool<AsyncPgConnection>, id: i64, ) -> Pin<Box<dyn Future<Output = Result<Option<Value>, AdminError>> + Send + '_>>; fn create( &self, pool: &Pool<AsyncPgConnection>, data: Value, ) -> Pin<Box<dyn Future<Output = Result<Value, AdminError>> + Send + '_>>; fn update( &self, pool: &Pool<AsyncPgConnection>, id: i64, data: Value, ) -> Pin<Box<dyn Future<Output = Result<Value, AdminError>> + Send + '_>>; fn delete( &self, pool: &Pool<AsyncPgConnection>, id: i64, ) -> Pin<Box<dyn Future<Output = Result<(), AdminError>> + Send + '_>>; // Provided methods fn actions(&self) -> Vec<AdminAction> { ... } fn execute_action( &self, pool: &Pool<AsyncPgConnection>, action: &str, ids: Vec<i64>, ) -> Pin<Box<dyn Future<Output = Result<u64, AdminError>> + Send + '_>> { ... } fn record_display(&self, record: &Value) -> String { ... } fn per_page(&self) -> u64 { ... } fn count( &self, pool: &Pool<AsyncPgConnection>, ) -> Pin<Box<dyn Future<Output = Result<u64, AdminError>> + Send + '_>> { ... }
}
Expand description

The core trait that enables a model to be managed in the admin panel.

Implementors provide field metadata, CRUD operations, and display configuration. The admin plugin uses this trait to generate all views dynamically at runtime.

§Design notes

All data flows through serde_json::Value to keep the trait object-safe. The admin panel doesn’t need to know concrete types — it renders fields based on AdminField metadata and passes values as JSON.

Required Methods§

Source

fn slug(&self) -> &'static str

URL-safe slug for this model (e.g., “projects”, “tickets”). Used in admin URLs: /admin/projects/, /admin/projects/42/.

Source

fn display_name(&self) -> &'static str

Human-readable singular name (e.g., “Project”).

Source

fn display_name_plural(&self) -> &'static str

Human-readable plural name (e.g., “Projects”).

Source

fn fields(&self) -> Vec<AdminField>

Field metadata for this model.

Source

fn list( &self, pool: &Pool<AsyncPgConnection>, params: ListParams, ) -> Pin<Box<dyn Future<Output = Result<ListResult, AdminError>> + Send + '_>>

List records with pagination, search, sort, and filters.

Source

fn get( &self, pool: &Pool<AsyncPgConnection>, id: i64, ) -> Pin<Box<dyn Future<Output = Result<Option<Value>, AdminError>> + Send + '_>>

Get a single record by ID.

Source

fn create( &self, pool: &Pool<AsyncPgConnection>, data: Value, ) -> Pin<Box<dyn Future<Output = Result<Value, AdminError>> + Send + '_>>

Create a new record from form data.

Source

fn update( &self, pool: &Pool<AsyncPgConnection>, id: i64, data: Value, ) -> Pin<Box<dyn Future<Output = Result<Value, AdminError>> + Send + '_>>

Update an existing record.

Source

fn delete( &self, pool: &Pool<AsyncPgConnection>, id: i64, ) -> Pin<Box<dyn Future<Output = Result<(), AdminError>> + Send + '_>>

Delete a record by ID.

Provided Methods§

Source

fn actions(&self) -> Vec<AdminAction>

Available bulk actions (default: just “Delete selected”).

Source

fn execute_action( &self, pool: &Pool<AsyncPgConnection>, action: &str, ids: Vec<i64>, ) -> Pin<Box<dyn Future<Output = Result<u64, AdminError>> + Send + '_>>

Execute a bulk action on the given IDs.

Source

fn record_display(&self, record: &Value) -> String

Return a display string for a record (used in breadcrumbs, titles).

Defaults to "ModelName #id" (or "ModelName <no id>" when the record has no numeric id).

Source

fn per_page(&self) -> u64

Records per page in the list view. Override to taste.

Source

fn count( &self, pool: &Pool<AsyncPgConnection>, ) -> Pin<Box<dyn Future<Output = Result<u64, AdminError>> + Send + '_>>

Count records matching a list query (defaults to list(..., per_page: 0).total).

Override if the backend can count without materializing records.

Implementors§