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,
) -> AdminFuture<'_, ListResult>;
fn get(
&self,
pool: &Pool<AsyncPgConnection>,
id: i64,
) -> AdminFuture<'_, Option<Value>>;
fn create(
&self,
pool: &Pool<AsyncPgConnection>,
data: Value,
) -> AdminFuture<'_, Value>;
fn update(
&self,
pool: &Pool<AsyncPgConnection>,
id: i64,
data: Value,
) -> AdminFuture<'_, Value>;
fn delete(
&self,
pool: &Pool<AsyncPgConnection>,
id: i64,
) -> AdminFuture<'_, ()>;
// Provided methods
fn actions(&self) -> Vec<AdminAction> { ... }
fn execute_action(
&self,
pool: &Pool<AsyncPgConnection>,
action: &str,
ids: Vec<i64>,
) -> AdminFuture<'_, u64> { ... }
fn record_display(&self, record: &Value) -> String { ... }
fn per_page(&self) -> u64 { ... }
fn count(&self, pool: &Pool<AsyncPgConnection>) -> AdminFuture<'_, u64> { ... }
}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§
Sourcefn slug(&self) -> &'static str
fn slug(&self) -> &'static str
URL-safe slug for this model (e.g., “projects”, “tickets”).
Used in admin URLs: /admin/projects/, /admin/projects/42/.
Sourcefn display_name(&self) -> &'static str
fn display_name(&self) -> &'static str
Human-readable singular name (e.g., “Project”).
Sourcefn display_name_plural(&self) -> &'static str
fn display_name_plural(&self) -> &'static str
Human-readable plural name (e.g., “Projects”).
Sourcefn fields(&self) -> Vec<AdminField>
fn fields(&self) -> Vec<AdminField>
Field metadata for this model.
Sourcefn list(
&self,
pool: &Pool<AsyncPgConnection>,
params: ListParams,
) -> AdminFuture<'_, ListResult>
fn list( &self, pool: &Pool<AsyncPgConnection>, params: ListParams, ) -> AdminFuture<'_, ListResult>
List records with pagination, search, sort, and filters.
Sourcefn get(
&self,
pool: &Pool<AsyncPgConnection>,
id: i64,
) -> AdminFuture<'_, Option<Value>>
fn get( &self, pool: &Pool<AsyncPgConnection>, id: i64, ) -> AdminFuture<'_, Option<Value>>
Get a single record by ID.
Sourcefn create(
&self,
pool: &Pool<AsyncPgConnection>,
data: Value,
) -> AdminFuture<'_, Value>
fn create( &self, pool: &Pool<AsyncPgConnection>, data: Value, ) -> AdminFuture<'_, Value>
Create a new record from form data.
Sourcefn update(
&self,
pool: &Pool<AsyncPgConnection>,
id: i64,
data: Value,
) -> AdminFuture<'_, Value>
fn update( &self, pool: &Pool<AsyncPgConnection>, id: i64, data: Value, ) -> AdminFuture<'_, Value>
Update an existing record.
Sourcefn delete(&self, pool: &Pool<AsyncPgConnection>, id: i64) -> AdminFuture<'_, ()>
fn delete(&self, pool: &Pool<AsyncPgConnection>, id: i64) -> AdminFuture<'_, ()>
Delete a record by ID.
Provided Methods§
Sourcefn actions(&self) -> Vec<AdminAction>
fn actions(&self) -> Vec<AdminAction>
Available bulk actions (default: just “Delete selected”).
Sourcefn execute_action(
&self,
pool: &Pool<AsyncPgConnection>,
action: &str,
ids: Vec<i64>,
) -> AdminFuture<'_, u64>
fn execute_action( &self, pool: &Pool<AsyncPgConnection>, action: &str, ids: Vec<i64>, ) -> AdminFuture<'_, u64>
Execute a bulk action on the given IDs.
Sourcefn record_display(&self, record: &Value) -> String
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).
Sourcefn count(&self, pool: &Pool<AsyncPgConnection>) -> AdminFuture<'_, u64>
fn count(&self, pool: &Pool<AsyncPgConnection>) -> AdminFuture<'_, u64>
Count records matching a list query (defaults to list(..., per_page: 0).total).
Override if the backend can count without materializing records.