aboutsummaryrefslogtreecommitdiff
path: root/examples/tutorial02/polls/models.rs
blob: 48e58cc03a1d0d338aefa9cbf490dcedd76a928c (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::{gather, Id, Model};

#[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!();