Attribute Macro metamorphose::Model[][src]

#[Model]
Expand description

Macro for converting Structure to mango-orm Model. The model can access the database. The model can create, update, and delete documents in collections.

Example:

use mango_orm::*;
use metamorphose::Model;
use serde::{Deserialize, Serialize};

// Get settings of service/sub-application.
use crate::settings::{
    default::{DATABASE_NAME, DB_CLIENT_NAME, DB_QUERY_DOCS_LIMIT, SERVICE_NAME},
    PROJECT_NAME, UNIQUE_PROJECT_KEY,
};

#[Model(
    is_del_docs = false,
    is_use_add_valid = true,
    ignore_fields = "confirm_password"
)]
#[derive(Serialize, Deserialize, Default, Debug)]
pub struct AdminProfile {
   #[serde(default)]
   #[field_attrs(
       widget = "inputText",
       label = "Username",
       placeholder = "Enter your username",
       unique = true,
       required = true,
       maxlength = 150,
       hint = "Valid characters: a-z A-Z 0-9 _ @ + .<br>Max size: 150"
   )]
   pub username: Option<String>,
   //
   #[serde(default)]
   #[field_attrs(
       widget = "inputImage",
       label = "Photo",
       value = r#"{
               "path":"./media/no_avatar.png",
               "url":"/media/no_avatar.png"
           }"#,
       placeholder = "Upload your photo",
       accept = "image/jpeg,image/png",
       hint = "Image in JPEG or PNG format",
       thumbnails = r#"[["xs",150],["sm",300]]"#
   )]
   pub photo: Option<String>,
   //
   #[serde(default)]
   #[field_attrs(
       widget = "inputText",
       label = "First name",
       placeholder = "Enter your First name",
       maxlength = 150
   )]
   pub first_name: Option<String>,
   //
   #[serde(default)]
   #[field_attrs(
       widget = "inputText",
       label = "Last name",
       placeholder = "Enter your Last name",
       maxlength = 150
   )]
   pub last_name: Option<String>,
   //
   #[serde(default)]
   #[field_attrs(
       widget = "inputEmail",
       label = "E-mail",
       placeholder = "Please enter your email",
       required = true,
       unique = true,
       maxlength = 320,
       hint = "Your actual E-mail"
   )]
   pub email: Option<String>,
   //
   #[serde(default)]
   #[field_attrs(
       widget = "inputPhone",
       label = "Phone number",
       placeholder = "Please enter your phone number",
       unique = true,
       maxlength = 30,
       hint = "Your actual phone number"
   )]
   pub phone: Option<String>,
   //
   #[serde(default)]
   #[field_attrs(
       widget = "inputPassword",
       label = "Password",
       placeholder = "Enter your password",
       required = true,
       minlength = 8,
       hint = "Valid characters: a-z A-Z 0-9 @ # $ % ^ & + = * ! ~ ) (<br>Min size: 8"
   )]
   pub password: Option<String>,
   //
   #[serde(default)]
   #[field_attrs(
       widget = "inputPassword",
       label = "Confirm password",
       placeholder = "Repeat your password",
       required = true,
       minlength = 8,
       hint = "Repeat your password"
   )]
   pub confirm_password: Option<String>,
   //
   #[serde(default)]
   #[field_attrs(
       widget = "checkBox",
       label = "is staff?",
       hint = "User can access the admin site?"
   )]
   pub is_staff: Option<bool>,
   //
   #[serde(default)]
   #[field_attrs(
       widget = "checkBox",
       label = "is active?",
       hint = "Is this an active account?"
   )]
   pub is_active: Option<bool>,
}