Heads up! To view this whole video, sign in with your Courses account or enroll in your free 7-day trial. Sign In Enroll
Preview
Start a free Courses trial
to watch this video
We should nail down what we want our app to do. Let's stub out most of it with comments.
This video doesn't have any notes.
Related Discussions
Have questions about this video? Start a discussion with the community and Treehouse staff.
Sign upRelated Discussions
Have questions about this video? Start a discussion with the community and Treehouse staff.
Sign up
[MUSIC]
0:00
What I wanna make is a simple command line
application that will let me record
0:04
thoughts or notes, stick a time stamp on
them, and save them to a database.
0:08
I should also be able to page through all
of them in some sort of order.
0:12
I'll want to delete the ones I don't need
anymore.
0:15
And I'd love to able to search for phrases
in all of the posts.
0:17
I bet we can do all this in about 100
lines of code.
0:21
What do you think?
0:22
So, I've gone ahead, and made a file
called diary.py.
0:24
You can call this journal.py or whatever,
if you don't like the word, diary.
0:27
And again, of course, we need to import
everything from peewee.
0:33
So, from peewee, import *.
0:36
And, just like last time, we need a
database, and a model.
0:40
So my database, I'm gonna do again, Sqlite
database, and I'm gonna say diary.db.
0:44
And then I'm gonna create my model, which
I'm gonna call entry.
0:53
And again, it extends from Model.
0:58
So, what I wanna have in here is I wanna
have content.
1:00
I wanna have a timestamp.
1:04
The Meta is gonna be database equals db.
1:08
Yeah?
All right.
1:11
We're gonna have a menu.
1:16
So, I need to be able to show that menu.
1:18
This should be something that runs
continuously like all
1:20
the menus that we've done in the past.
1:24
So, you know, probably want to have a
while loop.
1:26
But I, I wanna make sure and
1:29
have this in a function cuz I don't want
the script to just run all the time.
1:30
I, just, it's a little bit nicer
organization.
1:35
So, let's call this menu loop.
1:38
And we'll say, Show the menu.
1:41
All right.
1:44
So, we know we're gonna have some crud.
1:46
We're gonna do creating, and reading, and
probably wanna do updating.
1:50
But we'll do creating, reading, and
deleting.
1:53
So, we should make functions for that.
1:55
So let's do an add entry.
1:57
And we're gonna say Add an entry.
2:02
Always important to have your docstrings
kids.
2:07
Just remember to keep those in there.
2:12
And then for the reading part let's say
view entries.
2:14
We're gonna look at all the entries, and
we'll say View previous entries.
2:18
And then we're gonna have a way to delete,
so, let's say delete entry.
2:25
And I think that's probably gonna get an
entry passed to it.
2:31
And we'll say Delete an entry.
2:35
All right.
2:39
And then like I said, I wanna, I wanna be
able to run this file so that it runs, but
2:40
if I ever wanna import these into
something else, like maybe I wanna turn
2:45
this diary that works great on the command
line into something I can use from Flask.
2:49
I'd wanna import this, I don't want stuff
to just run when I import it.
2:55
So, we're going to add another one of
those if name blocks.
2:59
So, if name is equal to main.
3:04
And then we're gonna have the menu, so,
we're going to run menu loop.
3:07
So, okay.
3:12
I think that's what we need to have in
order to get everything.
3:14
We'll flush this out as we go along.
3:18
Maybe my hundred line estimate isn't so
great, but it's just comments so far.
3:21
Okay, let's get connected to the database
and write our model.
3:25
You need to sign up for Treehouse in order to download course files.
Sign upYou need to sign up for Treehouse in order to set up Workspace
Sign up