Skip to main content

ModelAdmin

Trait ModelAdmin 

Source
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 { ... }
}
Available on 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§

Source

fn model_name(&self) -> &str

Get the model name

Provided Methods§

Source

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.

Source

fn pk_field(&self) -> &str

Get the primary key field name

By default, returns “id”.

Source

fn list_display(&self) -> Vec<&str>

Fields to display in list view

Source

fn list_filter(&self) -> Vec<&str>

Fields that can be used for filtering

Source

fn search_fields(&self) -> Vec<&str>

Fields that can be searched

Source

fn fields(&self) -> Option<Vec<&str>>

Fields to display in forms (None = all fields)

Source

fn readonly_fields(&self) -> Vec<&str>

Read-only fields

Source

fn ordering(&self) -> Vec<&str>

Ordering for list view (prefix with “-” for descending)

Source

fn list_per_page(&self) -> Option<usize>

Number of items per page (None = use site default)

Source

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.

Source

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.

Source

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.

Source

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".

Implementors§