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§
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,
) -> Pin<Box<dyn Future<Output = Result<ListResult, AdminError>> + Send + '_>>
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.
Sourcefn get(
&self,
pool: &Pool<AsyncPgConnection>,
id: i64,
) -> Pin<Box<dyn Future<Output = Result<Option<Value>, AdminError>> + Send + '_>>
fn get( &self, pool: &Pool<AsyncPgConnection>, id: i64, ) -> Pin<Box<dyn Future<Output = Result<Option<Value>, AdminError>> + Send + '_>>
Get a single record by ID.
Sourcefn create(
&self,
pool: &Pool<AsyncPgConnection>,
data: Value,
) -> Pin<Box<dyn Future<Output = Result<Value, AdminError>> + Send + '_>>
fn create( &self, pool: &Pool<AsyncPgConnection>, data: Value, ) -> Pin<Box<dyn Future<Output = Result<Value, AdminError>> + Send + '_>>
Create a new record from form data.
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>,
) -> Pin<Box<dyn Future<Output = Result<u64, AdminError>> + Send + '_>>
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.
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).