From 311b49a2fdd97b8b870dbaccccb55058ee0207c8 Mon Sep 17 00:00:00 2001 From: Melody Horn / boringcactus Date: Sun, 13 Jun 2021 16:33:46 -0600 Subject: lay groundwork for models --- examples/tutorial02/polls/models.rs | 21 +++++++++++++++++++++ 1 file changed, 21 insertions(+) create mode 100644 examples/tutorial02/polls/models.rs (limited to 'examples/tutorial02/polls/models.rs') 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, + #[model(max_length=200)] + question_text: String, + /// date published + pub_date: time::PrimitiveDateTime, +} + +#[derive(Model)] +pub struct Choice { + id: Option, + #[model(Question, on_delete=Cascade)] + question: Id, + #[model(max_length=200)] + choice_text: String, + #[model(default = 0)] + votes: usize, +} -- cgit v1.2.3