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/mod.rs | 11 +++++++++++ examples/tutorial02/polls/models.rs | 21 +++++++++++++++++++++ examples/tutorial02/polls/urls.rs | 9 +++++++++ examples/tutorial02/polls/views.rs | 5 +++++ 4 files changed, 46 insertions(+) create mode 100644 examples/tutorial02/polls/mod.rs create mode 100644 examples/tutorial02/polls/models.rs create mode 100644 examples/tutorial02/polls/urls.rs create mode 100644 examples/tutorial02/polls/views.rs (limited to 'examples/tutorial02/polls') 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, + #[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, +} 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() +} -- cgit v1.2.3