# Actix Admin
The actix-admin crate aims at creating a web admin interface similar to other admin interfaces (such as flask-admin in python).
## Getting Started
cargo run
.See the step by step tutorial
Supports custom views which are added to the Navbar
itertools = "0.10.3" sea-orm = { version = "^0.9.1", features = [ "sqlx-sqlite", "runtime-actix-native-tls", "macros" ], default-features = true } actix_admin = { version = "^0.1.0" }
``` use seaorm::entity::prelude::*; use serde::{Deserialize, Serialize}; use actixadmin::prelude::; use actix_web::web; use actix_web::App; use actix_web::HttpServer; use sea_orm::entity::prelude::; use seaorm::entity::prelude::*; use actixadmin::prelude::; // 1. Import ActixAdmin use actix_admin::prelude::;
// 2. Use DeriveActixAmin* Macros to implement the traits for the model
DeriveActixAdmin, DeriveActixAdminModel, DeriveActixAdminViewModel )]
pub struct Model {
#[seaorm(primarykey)]
#[serde(skipdeserializing)]
#[actixadmin(primary_key)]
pub id: i32,
pub comment: String
}
impl ActixAdminModelValidationTrait
pub enum Relation { }
// 3. Add actix-admin to the AppState
pub struct AppState { pub db: DatabaseConnection, pub actix_admin: ActixAdmin, }
// 4. Implement the ActixAdminAppDataTrait for the AppState impl ActixAdminAppDataTrait for AppState { fn get_db(&self) -> &DatabaseConnection { &self.db }
fn getactixadmin(&self) -> &ActixAdmin { &self.actix_admin } }
// 5. Setup the actix admin configuration pub fn createactixadminbuilder() -> ActixAdminBuilder { let commentview_model = ActixAdminViewModel::from(Entity);
let configuration = ActixAdminConfiguration { enableauth: false, userisloggedin: None, loginlink: None, logoutlink: None, };
let mut adminbuilder = ActixAdminBuilder::new(configuration);
adminbuilder.addentity::
admin_builder }
// 6. Add to the actix app let actixadmin = createactixadminbuilder().getactixadmin(); //let opt = ConnectOptions::new("sqlite::memory:".toowned()); //let conn = seaorm::Database::connect(opt).unwrap(); //let appstate = AppState { // db: conn, // actixadmin: actix_admin, //};
HttpServer::new(move || {
App::new()
//.appdata(web::Data::new(appstate.clone()))
.service(
createactixadminbuilder().getscope::
The admin interface will be available under /admin/.