Guide chapters
Admin panel
The Cot admin panel provides an automatic interface for managing your models. It allows you to add, edit, delete and view records without writing any custom views or templates. This is perfect for prototyping your application and for managing your data in cases where you don’t need a custom interface, as the Cot admin panel is automatically generated based on your models.
Enabling the Admin Interface
First, add the admin app and the dependencies required to your project in src/main.rs
:
use ;
use ;
use ;
use ;
use ;
;
Admin User Creation
By default, the admin interface uses Cot’s authentication system. Therefore, you need to create an admin user if it doesn’t exist:
use ;
use ;
use ;
// In your main.rs:
Registering Models in the Admin
To make your models appear in the admin interface, you need to implement the AdminModel
trait. The easiest way is to use the #[derive(AdminModel)]
macro:
use ;
use ;
use ;
Note however that in order to derive the AdminModel
trait, you need to also derive the Form
and Model
traits (the latter is provided by the #[model]
attribute). In addition to that, your model needs to implement the Display
trait—for instance, in the case above, we could add it like so:
After adding the AdminModel
trait, you can add your model to the admin panel using DefaultAdminModelManager
. This is as easy as adding the following code to your App
implementation:
Now your model can be managed through the admin interface at http://localhost:8000/admin/
!
Summary
In this chapter, you learned how to enable the Cot admin panel, create an admin user, and register your models in the admin interface. In the next chapter, we’ll learn how to handle static assets in Cot.