diff options
author | Melody Horn / boringcactus <melody@boringcactus.com> | 2021-06-13 16:33:46 -0600 |
---|---|---|
committer | Melody Horn / boringcactus <melody@boringcactus.com> | 2021-06-13 16:33:46 -0600 |
commit | 311b49a2fdd97b8b870dbaccccb55058ee0207c8 (patch) | |
tree | 1ca431733526cac1c7c2f7f1bfda7324ae088d50 /examples/tutorial02/polls/models.rs | |
parent | cc7d316e588c21de1023d6a76d4ea5e7b893977a (diff) | |
download | tosin-311b49a2fdd97b8b870dbaccccb55058ee0207c8.tar.gz tosin-311b49a2fdd97b8b870dbaccccb55058ee0207c8.zip |
lay groundwork for models
Diffstat (limited to 'examples/tutorial02/polls/models.rs')
-rw-r--r-- | examples/tutorial02/polls/models.rs | 21 |
1 files changed, 21 insertions, 0 deletions
diff --git a/examples/tutorial02/polls/models.rs b/examples/tutorial02/polls/models.rs new file mode 100644 index 0000000..5ed52c5 --- /dev/null +++ b/examples/tutorial02/polls/models.rs @@ -0,0 +1,21 @@ +use tosin::db::models::{Model, Id}; + +#[derive(Model)] +pub struct Question { + id: Option<Id>, + #[model(max_length=200)] + question_text: String, + /// date published + pub_date: time::PrimitiveDateTime, +} + +#[derive(Model)] +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, +} |