aboutsummaryrefslogtreecommitdiff
path: root/examples/tutorial02/polls/models.rs
blob: c9de156ba3518163a7be15ac934a9b1c58d503aa (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
use tosin::db::models::{Model, Id, gather};

#[derive(Model, PartialEq, Debug)]
pub struct Question {
    id: Option<Id>,
    #[model(max_length=200)]
    question_text: String,
    /// date published
    pub_date: chrono::NaiveDateTime,
}

#[derive(Model, PartialEq, Debug)]
pub struct Choice {
    id: Option<Id>,
    #[model(Question, on_delete=Cascade)]
    question: Id,
    #[model(max_length=200)]
    choice_text: String,
    #[model(default = 0)]
    votes: usize,
}

gather!();