2022-08-06 20:09:30 +02:00
|
|
|
use sea_orm::entity::prelude::*;
|
|
|
|
use serde::{Deserialize, Serialize};
|
|
|
|
use actix_admin::prelude::*;
|
2022-08-20 20:54:39 +02:00
|
|
|
use super::Post;
|
2022-08-06 20:09:30 +02:00
|
|
|
|
2022-08-18 13:56:38 +02:00
|
|
|
#[derive(Clone, Debug, PartialEq, DeriveEntityModel, Deserialize, Serialize, DeriveActixAdmin, DeriveActixAdminModel, DeriveActixAdminViewModel)]
|
2022-08-06 20:09:30 +02:00
|
|
|
#[sea_orm(table_name = "comment")]
|
|
|
|
pub struct Model {
|
|
|
|
#[sea_orm(primary_key)]
|
|
|
|
#[serde(skip_deserializing)]
|
|
|
|
#[actix_admin(primary_key)]
|
|
|
|
pub id: i32,
|
|
|
|
pub comment: String,
|
|
|
|
#[sea_orm(column_type = "Text")]
|
2023-02-15 12:18:24 +01:00
|
|
|
#[actix_admin(html_input_type = "email", list_regex_mask= "^([a-zA-Z]*)")]
|
2022-08-06 20:09:30 +02:00
|
|
|
pub user: String,
|
|
|
|
#[sea_orm(column_type = "DateTime")]
|
|
|
|
pub insert_date: DateTime,
|
2022-08-20 20:54:39 +02:00
|
|
|
pub is_visible: bool,
|
|
|
|
#[actix_admin(select_list="Post")]
|
|
|
|
pub post_id: Option<i32>,
|
|
|
|
pub my_decimal: Decimal
|
2022-08-06 20:09:30 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
#[derive(Copy, Clone, Debug, EnumIter, DeriveRelation)]
|
2022-08-20 20:54:39 +02:00
|
|
|
pub enum Relation {
|
|
|
|
#[sea_orm(
|
|
|
|
belongs_to = "super::post::Entity",
|
|
|
|
from = "Column::PostId",
|
|
|
|
to = "super::post::Column::Id"
|
|
|
|
)]
|
|
|
|
Post,
|
|
|
|
}
|
|
|
|
|
|
|
|
impl Related<super::post::Entity> for Entity {
|
|
|
|
fn to() -> RelationDef {
|
|
|
|
Relation::Post.def()
|
|
|
|
}
|
|
|
|
}
|
2022-08-06 20:09:30 +02:00
|
|
|
|
2022-08-20 22:51:15 +02:00
|
|
|
impl ActiveModelBehavior for ActiveModel {}
|
|
|
|
|
|
|
|
impl ActixAdminModelValidationTrait<ActiveModel> for Entity {
|
|
|
|
fn validate(model: &ActiveModel) -> HashMap<String, String> {
|
|
|
|
let mut errors = HashMap::new();
|
|
|
|
if model.my_decimal.clone().unwrap() < Decimal::from(100 as i16) {
|
|
|
|
errors.insert("my_decimal".to_string(), "Must be larger than 100".to_string());
|
|
|
|
}
|
2023-02-03 18:06:14 +01:00
|
|
|
|
2022-08-20 22:51:15 +02:00
|
|
|
errors
|
|
|
|
}
|
|
|
|
}
|