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 | |
parent | cc7d316e588c21de1023d6a76d4ea5e7b893977a (diff) | |
download | tosin-311b49a2fdd97b8b870dbaccccb55058ee0207c8.tar.gz tosin-311b49a2fdd97b8b870dbaccccb55058ee0207c8.zip |
lay groundwork for models
Diffstat (limited to 'examples/tutorial02/polls')
-rw-r--r-- | examples/tutorial02/polls/mod.rs | 11 | ||||
-rw-r--r-- | examples/tutorial02/polls/models.rs | 21 | ||||
-rw-r--r-- | examples/tutorial02/polls/urls.rs | 9 | ||||
-rw-r--r-- | examples/tutorial02/polls/views.rs | 5 |
4 files changed, 46 insertions, 0 deletions
diff --git a/examples/tutorial02/polls/mod.rs b/examples/tutorial02/polls/mod.rs new file mode 100644 index 0000000..f4fde54 --- /dev/null +++ b/examples/tutorial02/polls/mod.rs @@ -0,0 +1,11 @@ +use tosin::apps::AppConfig; + +pub mod models; +pub mod urls; +pub mod views; + +pub use urls::urls; + +pub const APP: AppConfig = AppConfig { + +}; 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, +} diff --git a/examples/tutorial02/polls/urls.rs b/examples/tutorial02/polls/urls.rs new file mode 100644 index 0000000..04d93cc --- /dev/null +++ b/examples/tutorial02/polls/urls.rs @@ -0,0 +1,9 @@ +use tosin::urls::{UrlMap, url_map}; + +use super::views; + +pub fn urls() -> UrlMap { + url_map! { + => views::index, // TODO name: "index" + } +} diff --git a/examples/tutorial02/polls/views.rs b/examples/tutorial02/polls/views.rs new file mode 100644 index 0000000..4859cec --- /dev/null +++ b/examples/tutorial02/polls/views.rs @@ -0,0 +1,5 @@ +use tosin::http::{Reply, Response}; + +pub fn index() -> Response { + "Hello, world. You're at the polls index.".into_response() +} |