Trait AdminModelManager

Source
pub trait AdminModelManager: Send + Sync {
    // Required methods
    fn name(&self) -> &str;
    fn url_name(&self) -> &str;
    fn get_objects<'life0, 'life1, 'async_trait>(
        &'life0 self,
        request: &'life1 Request,
    ) -> Pin<Box<dyn Future<Output = Result<Vec<Box<dyn AdminModel>>>> + Send + 'async_trait>>
       where Self: 'async_trait,
             'life0: 'async_trait,
             'life1: 'async_trait;
    fn get_object_by_id<'life0, 'life1, 'life2, 'async_trait>(
        &'life0 self,
        request: &'life1 Request,
        id: &'life2 str,
    ) -> Pin<Box<dyn Future<Output = Result<Option<Box<dyn AdminModel>>>> + Send + 'async_trait>>
       where Self: 'async_trait,
             'life0: 'async_trait,
             'life1: 'async_trait,
             'life2: 'async_trait;
    fn form_context(&self) -> Box<dyn FormContext>;
    fn form_context_from_object(
        &self,
        object: Box<dyn AdminModel>,
    ) -> Box<dyn FormContext>;
    fn save_from_request<'life0, 'life1, 'life2, 'async_trait>(
        &'life0 self,
        request: &'life1 mut Request,
        object_id: Option<&'life2 str>,
    ) -> Pin<Box<dyn Future<Output = Result<Option<Box<dyn FormContext>>>> + Send + 'async_trait>>
       where Self: 'async_trait,
             'life0: 'async_trait,
             'life1: 'async_trait,
             'life2: 'async_trait;
    fn remove_by_id<'life0, 'life1, 'life2, 'async_trait>(
        &'life0 self,
        request: &'life1 mut Request,
        object_id: &'life2 str,
    ) -> Pin<Box<dyn Future<Output = Result<()>> + Send + 'async_trait>>
       where Self: 'async_trait,
             'life0: 'async_trait,
             'life1: 'async_trait,
             'life2: 'async_trait;
}
Expand description

A trait for adding admin models to the app.

This exposes an API over AdminModel that is dyn-compatible and hence can be dynamically added to the project.

See DefaultAdminModelManager for an automatic implementation of this trait.

Required Methods§

Source

fn name(&self) -> &str

Returns the display name of the model.

Source

fn url_name(&self) -> &str

Returns the URL slug for the model.

Source

fn get_objects<'life0, 'life1, 'async_trait>( &'life0 self, request: &'life1 Request, ) -> Pin<Box<dyn Future<Output = Result<Vec<Box<dyn AdminModel>>>> + Send + 'async_trait>>
where Self: 'async_trait, 'life0: 'async_trait, 'life1: 'async_trait,

Returns the list of objects of this model.

Source

fn get_object_by_id<'life0, 'life1, 'life2, 'async_trait>( &'life0 self, request: &'life1 Request, id: &'life2 str, ) -> Pin<Box<dyn Future<Output = Result<Option<Box<dyn AdminModel>>>> + Send + 'async_trait>>
where Self: 'async_trait, 'life0: 'async_trait, 'life1: 'async_trait, 'life2: 'async_trait,

Returns the object with the given ID.

Source

fn form_context(&self) -> Box<dyn FormContext>

Returns an empty form context for this model.

Source

fn form_context_from_object( &self, object: Box<dyn AdminModel>, ) -> Box<dyn FormContext>

Returns a form context pre-filled with the data from given object.

It is guaranteed that object parameter is an object returned by either [get_objects] or [get_object_by_id] methods. This means that if you always return the same object type from these methods, you can safely downcast the object to the same type in this method as well.

Source

fn save_from_request<'life0, 'life1, 'life2, 'async_trait>( &'life0 self, request: &'life1 mut Request, object_id: Option<&'life2 str>, ) -> Pin<Box<dyn Future<Output = Result<Option<Box<dyn FormContext>>>> + Send + 'async_trait>>
where Self: 'async_trait, 'life0: 'async_trait, 'life1: 'async_trait, 'life2: 'async_trait,

Saves the object by using the form data from given request.

§Errors

Returns an error if the object could not be saved, for instance due to a database error.

Source

fn remove_by_id<'life0, 'life1, 'life2, 'async_trait>( &'life0 self, request: &'life1 mut Request, object_id: &'life2 str, ) -> Pin<Box<dyn Future<Output = Result<()>> + Send + 'async_trait>>
where Self: 'async_trait, 'life0: 'async_trait, 'life1: 'async_trait, 'life2: 'async_trait,

Removes the object with the given ID.

§Errors

Returns an error if the object with the given ID does not exist.

Returns an error if the object could not be removed, for instance due to a database error.

Implementors§