pub trait ModelAdmin: Send + Sync {
Show 14 methods
// Required method
fn model_name(&self) -> &str;
// Provided methods
fn table_name(&self) -> &str { ... }
fn pk_field(&self) -> &str { ... }
fn list_display(&self) -> Vec<&str> { ... }
fn list_filter(&self) -> Vec<&str> { ... }
fn search_fields(&self) -> Vec<&str> { ... }
fn fields(&self) -> Option<Vec<&str>> { ... }
fn readonly_fields(&self) -> Vec<&str> { ... }
fn ordering(&self) -> Vec<&str> { ... }
fn list_per_page(&self) -> Option<usize> { ... }
fn has_view_permission<'life0, 'life1, 'async_trait>(
&'life0 self,
_user: &'life1 dyn AdminUser,
) -> Pin<Box<dyn Future<Output = bool> + Send + 'async_trait>>
where Self: 'async_trait,
'life0: 'async_trait,
'life1: 'async_trait { ... }
fn has_add_permission<'life0, 'life1, 'async_trait>(
&'life0 self,
_user: &'life1 dyn AdminUser,
) -> Pin<Box<dyn Future<Output = bool> + Send + 'async_trait>>
where Self: 'async_trait,
'life0: 'async_trait,
'life1: 'async_trait { ... }
fn has_change_permission<'life0, 'life1, 'async_trait>(
&'life0 self,
_user: &'life1 dyn AdminUser,
) -> Pin<Box<dyn Future<Output = bool> + Send + 'async_trait>>
where Self: 'async_trait,
'life0: 'async_trait,
'life1: 'async_trait { ... }
fn has_delete_permission<'life0, 'life1, 'async_trait>(
&'life0 self,
_user: &'life1 dyn AdminUser,
) -> Pin<Box<dyn Future<Output = bool> + Send + 'async_trait>>
where Self: 'async_trait,
'life0: 'async_trait,
'life1: 'async_trait { ... }
}server only.Expand description
Trait for configuring model administration
Implement this trait to customize how a model is displayed and edited in the admin.
Required Methods§
Sourcefn model_name(&self) -> &str
fn model_name(&self) -> &str
Get the model name
Provided Methods§
Sourcefn table_name(&self) -> &str
fn table_name(&self) -> &str
Get the database table name
By default, returns an empty string as a placeholder. Implementors should override this to return the actual table name.
Sourcefn list_display(&self) -> Vec<&str>
fn list_display(&self) -> Vec<&str>
Fields to display in list view
Sourcefn list_filter(&self) -> Vec<&str>
fn list_filter(&self) -> Vec<&str>
Fields that can be used for filtering
Sourcefn search_fields(&self) -> Vec<&str>
fn search_fields(&self) -> Vec<&str>
Fields that can be searched
Sourcefn readonly_fields(&self) -> Vec<&str>
fn readonly_fields(&self) -> Vec<&str>
Read-only fields
Sourcefn list_per_page(&self) -> Option<usize>
fn list_per_page(&self) -> Option<usize>
Number of items per page (None = use site default)
Sourcefn has_view_permission<'life0, 'life1, 'async_trait>(
&'life0 self,
_user: &'life1 dyn AdminUser,
) -> Pin<Box<dyn Future<Output = bool> + Send + 'async_trait>>where
Self: 'async_trait,
'life0: 'async_trait,
'life1: 'async_trait,
fn has_view_permission<'life0, 'life1, 'async_trait>(
&'life0 self,
_user: &'life1 dyn AdminUser,
) -> Pin<Box<dyn Future<Output = bool> + Send + 'async_trait>>where
Self: 'async_trait,
'life0: 'async_trait,
'life1: 'async_trait,
Check if user has permission to view this model
Default implementation denies all access (deny-by-default). Override this method to grant view permission based on user attributes.
§Migration from previous versions
Previously, this method accepted &(dyn std::any::Any + Send + Sync).
It now accepts &dyn AdminUser for type-safe permission checks.
Sourcefn has_add_permission<'life0, 'life1, 'async_trait>(
&'life0 self,
_user: &'life1 dyn AdminUser,
) -> Pin<Box<dyn Future<Output = bool> + Send + 'async_trait>>where
Self: 'async_trait,
'life0: 'async_trait,
'life1: 'async_trait,
fn has_add_permission<'life0, 'life1, 'async_trait>(
&'life0 self,
_user: &'life1 dyn AdminUser,
) -> Pin<Box<dyn Future<Output = bool> + Send + 'async_trait>>where
Self: 'async_trait,
'life0: 'async_trait,
'life1: 'async_trait,
Check if user has permission to add instances
Default implementation denies all access (deny-by-default). Override this method to grant add permission based on user attributes.
Sourcefn has_change_permission<'life0, 'life1, 'async_trait>(
&'life0 self,
_user: &'life1 dyn AdminUser,
) -> Pin<Box<dyn Future<Output = bool> + Send + 'async_trait>>where
Self: 'async_trait,
'life0: 'async_trait,
'life1: 'async_trait,
fn has_change_permission<'life0, 'life1, 'async_trait>(
&'life0 self,
_user: &'life1 dyn AdminUser,
) -> Pin<Box<dyn Future<Output = bool> + Send + 'async_trait>>where
Self: 'async_trait,
'life0: 'async_trait,
'life1: 'async_trait,
Check if user has permission to change instances
Default implementation denies all access (deny-by-default). Override this method to grant change permission based on user attributes.
Sourcefn has_delete_permission<'life0, 'life1, 'async_trait>(
&'life0 self,
_user: &'life1 dyn AdminUser,
) -> Pin<Box<dyn Future<Output = bool> + Send + 'async_trait>>where
Self: 'async_trait,
'life0: 'async_trait,
'life1: 'async_trait,
fn has_delete_permission<'life0, 'life1, 'async_trait>(
&'life0 self,
_user: &'life1 dyn AdminUser,
) -> Pin<Box<dyn Future<Output = bool> + Send + 'async_trait>>where
Self: 'async_trait,
'life0: 'async_trait,
'life1: 'async_trait,
Check if user has permission to delete instances
Default implementation denies all access (deny-by-default). Override this method to grant delete permission based on user attributes.
Dyn Compatibility§
This trait is dyn compatible.
In older versions of Rust, dyn compatibility was called "object safety".