Detailed Notes
We tackle query string values in this lesson so we can easily pass data around.
You can view source for today and all prior days by reviewing the tag Day 33 at this GitHub: https://github.com/robbroadhead/develpreneur-pythontutorial
Transcript Text
[Music] hello and welcome back we're continuing our python and django tutorials and we're going to look at some self-referencing models and start building out a little bit of structure within our roadmaps and our goals first thing we want to do is let's start with this we're from our road maps we want to be able to come in and within our time frames have some structure so what i want to do is be able to look at like overall annual goals and i want first quarter to actually have annual goals as a parent the way we do that is within the model so we can go back within here and uh within time frame we had roadmap as a parent but now what we get to do is we're just going to call it parent and this time we can just call it self uh let's see and like that and so we're gonna have a parent and it doesn't like that self um so let's see we'll take a look at that real quick actually skip it i'm not going to dig into self i'm going to just go to uh time frame so now it's parent is just going to be another time frame it should clean that up but okay we'll let it clean it up in a minute and so now that alone if you remember uh if we look at our forms uh time frame oh we we're gonna have to add parent now and let's put parent first just because and we don't need to do anything special with it so we can go over here let's see i gotta clean a few of these things up let's close a couple of these out let's take a look a bit we're running time frame is not defined let's take a look at that again i may have to go back to that i may not be able to do time frame oh because it's not defined yet so i do need to use self and i think i can do it this way let's just check that real quick itself is not fun so let's take a look into that let's i'll go back over here and it's actually self it's a string and i do want to grab this because i need it as a parent i want it to be able to be uh null and blank oops i did not get the e so let's try that let's see what that does for me oh i forgot a comma so go back here let's see if it picked it up it did uh so i need to whoops first thing i need to do is i'm going to go over here and i need to do my make migrations and let's look at my model real quick so i'm going to do time frames but i also want uh okay tasks are tied to a time frame so i'm good there so i only need this one done so i'm going to make migrations now i'm going to migrate and did that oh i need to run it i'll get the server running again and so now let's go back to my roadmaps and now if i edit annual goals oh it did not come through i don't have my form coming through oh i'm sorry that's roadmap if i go to first quarter then i can set a parent uh it could be itself which is going to be useless but now i'm going to make it over all annual goals i'm going to save the record annual goals does not have one and so now let's go back to within road maps when i do edit a road map let's adjust this so that it goes by parent first so that you go under your parent so if i go to my view where's my view there's my view let's see actually first my mistake let's go ahead and what we want to do is here when we do first quarter we want to be able to within this editing of tasks i want to be able to go back to the quarter that we're working with so we want to go back to this time frame so that's easy enough to do what we're going to do is whoops let's go back to where that was viewed so this was in our time frame and this is an edit listing there so if we go to our time frame edit we can see here that we're doing uh we're doing that go page so now if we do go page and we add uh let's see we're just gonna do time frame equals uh this is going to be uh this guy which is oh wait let's form his table we come into there is this the edit yeah it's time frame edit and so we're going to have to do what did we call him let's go take a look at him i think we called him something let's see so if we go to time frame edit time frame edit edit time frame let's come in here time frame and we've got a form but let's just go ahead and do this to make it easy tfid and that is going to be equal to uh here which is an id so we're just going to send tfid in we got that and so now we can go to our edit and he's going to be tfid just keep it simple so now what we're going to do is we're going to see that this is going to come across let's just reset this one and so now when i do an edit i can see that i added this time frame id but that's not i'm not doing anything with it so now when i go to my edit for a task uh edit task is in here somewhere there we go so what i can do here is i can set uh let's keep it pretty simple is i'm going to add a parameter which is a parent uh we'll just keep it parent right now i'm not going to call it an id yeah let's do it that way let's just keep it simple parent id we're going to call it pid and now what we can do is we can do request dot get and then we're going to do tf which is what we called it so actually let's just print it for now because there's actually two things we're going to do because we're going to do pid here so we did this big if here now we've got to do an else because we have to handle the two so here print he's going to print it as a git he's going to print it as a post although i don't think we'll ever actually post but that's okay actually we'll probably just carry it across so we'll just keep it for now so let's just do it through this and so now we're going to do a print just to test it save it come in here and actually we can run this and if we go back and look we're gonna see in our output two there we go so we printed out r2 we can see here that's our get so now with that let's just let's play with this a little bit so here else and we're going to say uh parent id oops parent id equals this and we're going to do it as a string because i don't think we really care too well we're going to send both so let's do that because we're going to work with this a little bit let me do this so a parent we're going to default it to nothing but here if if we have that then we're going to do the uh because that's going to be parents so parent id equals and we're going to make it an int request.get and then we need to do a then parent is going to be equal to time frame dot objects dot get primary key equals the pid we do the same thing here for post uh params we're gonna add a parent and this can be equal to parent which may be a null oops i don't need that which may be a null or it may be a value not going to play with the post yet because we may be able to deal with that later we'll leave it for now uh so that gives us a parent so that means now that we can address the parent within the time frame editor and we're going to create a button here that says create task break break break break so let's go here i'm going to do so we're gonna if parent i need to end if so if i have a parent then i'm going to add another button and this one's going to be return to and we're going to do parent.name because that's what we called it otherwise he's going to go to time frame parent id so let's see how that works out so now let's go to our row actually go to a time frame first quarter if i edit this one it should be uh please update record and he's not giving me that yet so let's see that's task time frame 2.0 let's go take a look at that real quick it's not 2.0 but 2-0 let's see what it said uh let's make sure it's getting the right oh it's not a time frame my mistake it's not the time frame it is so i have a time frame too uh it is the oh it is time frame okay so let's go back and look at this real quick so i do edit task edit task parent equals that that's parent so let's just do this let's print that now let's prepare it oops and print the parent so went to task edit was i looking at task in it oops that was in time frame edit instead task edit okay my mistake uh let's get rid of that and i don't think i had parent anywhere else okay so i should go instead of time frame edit let's go to task edit and here uh let's just do it above the form so if parent i'm gonna put a little button here and i don't need that so now i take a look turn the first quarter and now i go back and i can see that so if i do that let's go back to my road maps annual goals if i go to overall annual goals then this one's returned to overall annual goals so now what i want to do is say the same thing and i'm going to do a parent for the time frame so here and it's going to get sort of complicated because what we're going to end up doing is we're going to have to sort of take that extra value across so we're going to do uh within roadmap so let's go back to roadmap so when it doesn't edit here on the roadmap i want to add a roadmap id which is going to be rm so if i go to roadmap edit it's going to go to a time frame and i'm going to give it roadmap equals which is going to be this guy so rmid and i'm going to do it basically the same way here so that means when i go to roadmap edit in my views roadmap create edit and then here i'm going to send my current rom id and i could do this a little differently but i'm just going to do it this way it's a little easier that way i'm going to come in and do that is equal to id that's right because i've already passed in so i'm just going to pass it through and so now when i do edit time frame uh let's see where actually let's take my i'm going to steal my edit task stuff real quick i'm going to take this well let's not worry about the parent part let's just do this if requests get let's do that and now oh i'm going to get rid of my prints because i don't need those i have a second print i did have another print there let's go to edit time frame and then here pop up so here's my else if i'm a post otherwise i'm gonna do it but now it's not tf it's rem whoops rm rm and that's not a time frame that's a road map uh parent id by a bam i don't need to print that i do need this to be parent and i want to do a parent here equals to null and i don't need that print but i do need this to be a post and now let's steal from my task edit where i did my parents i'm going to do the same thing i'm going to put that on my time frame and let's see i don't have any real buttons up there do i nope so i'm going to do it about my form again except for here i'm going to go to i think it's uh and i call it roadmap if i go to roadmap it is uh no it's roadmap parent id parent name okay so now i go to my roadmap annual goals uh let's see edit roadmap oh sorry for so annual goals will allow me to return to annual goals first quarter allows me return here but now here what i'm going to want to do on first quarter is i'm going to want that actually to return to apparent so i'm going to play around with this next time around is i'm going to start working on tweaking our query so we're only going to show parents and then within the parents they're going to show time frames that are child time frames so we go to an edit time frame we're going to see child time frames so we're going to see goals for the period and then child time frames so that take care of us for now we have once again run out of time as you can see you can start cranking through stuff but there's a lot of little details we're gonna do so next time around we've set our task list for that time so until then have yourself a great day a great week and we will talk to you next time you
Transcript Segments
[Music]
hello and welcome back
we're continuing our python and django
tutorials
and we're going to look at some
self-referencing models
and start building out a little bit of
structure within our roadmaps
and our goals first thing we want to do
is let's start with this we're from our
road maps we want to be able to come in
and within our time frames have some
structure so what i want to do is be
able to look at like overall annual
goals
and i want first quarter to actually
have annual goals as a
parent the way we do that is within the
model
so we can go back within here
and uh within time frame we had roadmap
as a parent but now what we get to do
is we're just going to call it parent
and this time we can just call it self
uh let's see and
like that and so we're gonna have a
parent
and it doesn't like that self
um so let's see we'll take a look at
that real quick
actually skip it i'm not going to dig
into self i'm going to just go
to uh time frame
so now it's parent is just going to be
another time frame it should
clean that up but okay we'll let it
clean it up in a minute
and so now that alone if you remember uh
if we look at our forms uh
time frame oh we we're gonna have to add
parent now
and let's put parent first just because
and we don't need to do anything special
with it
so we can go over here let's see i gotta
clean a few of these things up
let's close a couple of these out
let's take a look a bit we're running
time frame is not defined
let's take a look at that again i may
have to go back to that i may not be
able to do
time frame oh because it's not defined
yet
so i do need to use self
and i think i can do it this way let's
just check that real quick
itself is not fun so let's take a look
into that let's i'll go back over here
and it's
actually self it's a string
and i do want to grab this
because i need it as a parent i want it
to be able to be
uh null and blank oops i did not get the
e
so let's try that let's see what that
does for me
oh i forgot a comma so go back here
let's see if it picked it up it did uh
so i need to
whoops first thing i need to do is i'm
going to go over here
and i need to do my make migrations
and let's look at my model real quick so
i'm going to do time frames
but i also want uh okay tasks are tied
to a time frame so i'm good there so i
only need this one
done so i'm going to make migrations
now i'm going to migrate
and did that oh i need to run it i'll
get the server running again
and so now let's go back to my roadmaps
and now if i
edit annual goals
oh it did not come through i don't have
my form coming through
oh i'm sorry that's roadmap if i go to
first quarter
then i can set a parent uh it could be
itself which is going to be useless but
now i'm going to make it over all annual
goals
i'm going to save the record annual
goals does not have one
and so now let's go back to within road
maps
when i do edit a road map let's
adjust this so that it goes by parent
first
so that you go under your parent so if i
go to my view
where's my view there's my view
let's see actually first
my mistake let's go ahead and what we
want to do is here when we do first
quarter
we want to be able to within this
editing of tasks i want to be able to go
back to the quarter that we're working
with
so we want to go back to this time frame
so that's easy enough to do what we're
going to do is
whoops let's go back to where that was
viewed
so this was in our time frame and this
is an edit
listing there so if we go to our time
frame edit we can see here that we're
doing
uh we're doing that go page
so now if we do go page and we add
uh let's see we're just gonna do time
frame
equals uh
this is going to be
uh this guy which is
oh wait let's form his table we come
into there
is this the edit yeah it's time frame
edit
and so we're going to have to do
what did we call him let's go take a
look at him i think we called him
something let's see so if we go to time
frame edit time frame edit edit time
frame
let's come in here time frame
and we've got a form but let's just go
ahead and do
this to make it easy
tfid and that is going to be
equal to
uh here which is an id
so we're just going to send tfid in
we got that and so now we can go to our
edit
and he's going to be tfid just keep it
simple
so now what we're going to do is we're
going to see that this is going to come
across
let's just reset this one and so now
when i do an
edit i can see that
i added this time frame id but that's
not i'm not doing anything with it so
now
when i go to my edit for a task
uh edit task is in here somewhere
there we go so what i can do here
is i can set
uh let's keep it pretty simple is i'm
going to add a parameter
which is a parent
uh we'll just keep it parent right now
i'm not going to call it an id
yeah let's do it that way let's just
keep it simple parent id we're going to
call it pid
and now what we can do is we can do
request
dot get
and then we're going to do tf which is
what we called it so actually let's just
print it for now
because there's actually two things
we're going to do because we're going to
do pid here
so we did this big if here now we've got
to do
an else because we have to handle the
two so here
he's going to print it as a git he's
going to print it as a
post although i don't think we'll ever
actually post but that's okay
actually we'll probably just carry it
across so we'll just keep it for now so
let's just do it through this
and so now we're going to do a print
just to test it save it
come in here and actually we can run
this
and if we go back and look we're gonna
see in our output
two there we go so we printed out r2 we
can see here that's our get
so now
with that let's
just
let's play with this a little bit so
here else
and we're going to say uh parent id oops
parent id equals this and we're going to
do it as a string because i don't think
we really
care too well we're going to send both
so let's do that
because we're going to work with this a
little bit
let me do this so a parent
we're going to default it to nothing
but here
if
if we have that
then we're going to do the uh
because that's going to be parents so
parent id equals and we're going to make
it an
int request.get
and then we need to do a
then parent is going to be equal to time
frame
dot objects dot get primary key
equals the pid
we do the same thing here for post
uh params we're gonna add a parent
and this can be equal to parent which
may be a null oops i don't need that
which may be a null or it may be a value
not going to play with the post yet
because we may
be able to deal with that later we'll
leave it for now uh so that gives us a
parent so that means now that we can
address the parent within the
time frame editor
and we're going to create a button here
that says
create task break break break break so
let's go here
i'm going to do so we're gonna if
parent
i need to end if
so if i have a parent then i'm going to
add another button
and this one's going to be
return to
and we're going to do parent.name
because that's what we called it
otherwise he's going to go to time
frame
parent id
so let's see how that works out
so now let's go to our row actually go
to a time frame first quarter
if i edit this one it should be
uh please update record
and he's not giving me that yet so let's
see that's task time frame 2.0 let's go
take a look at that real quick
it's not 2.0 but 2-0 let's see what it
said
uh let's make sure it's getting the
right oh it's not a time frame
my mistake it's not the time frame it is
so i have a time frame too uh it is the
oh it is time frame okay so let's go
back and look at this real quick
so i do edit task
edit task
parent equals that that's parent
so let's just do this let's print
that
now let's prepare it oops
and print the parent
so went to task edit was i looking at
task in it
oops that was in time frame edit instead
task edit okay my mistake
uh let's get rid of that
and i don't think i had parent anywhere
else
okay so i should go instead of time
frame edit let's go to task edit
and here uh let's just do it above the
form
so if parent i'm gonna put a little
button here
and i don't need that so now
i take a look turn the first quarter
and now i go back and i can see that so
if i do that
let's go back to my road maps annual
goals
if i go to overall annual goals
then this one's returned to overall
annual goals so now what i want to do is
say
the same thing and i'm going to do a
parent for the time frame
so here
and it's going to get sort of
complicated because what we're going to
end up doing is we're going to have to
sort of
take that extra value across
so we're going to do
uh within roadmap so let's go back to
roadmap
so when it doesn't edit here on the
roadmap i want to add
a roadmap id which is going to be rm so
if i go to roadmap
edit
it's going to go to a time frame and i'm
going to give it roadmap
equals
which is going to be this guy so
rmid and i'm going to do it basically
the same way
here so that means when i go to
roadmap edit in my views
roadmap create edit
and then here
i'm going to send my current rom id and
i could do this a little differently but
i'm just going to do it this way it's a
little easier that way
i'm going to come in and do that is
equal to
id that's right because i've already
passed in so i'm just going to pass it
through
and so now when i do edit
time frame
uh let's see where actually let's take
my i'm going to steal my edit task stuff
real quick
i'm going to take this
well let's not worry about the parent
part let's just do this if requests get
let's do that
and now oh i'm going to get rid of my
prints because i don't need those
i have a second print i did have another
print there
let's go to edit time frame
and then here pop up
so here's my else if i'm a post
otherwise i'm gonna do it but now it's
not
tf it's rem whoops
rm
rm and that's not a time frame that's a
road map
uh parent id by a bam i don't need to
print that
i do need this to be parent
and i want to do a parent here equals to
null
and i don't need that print but i do
need this
to be a post
and now let's steal from my task edit
where i did my parents
i'm going to do the same thing i'm going
to put that on my time frame
and let's see i don't have any real
buttons up there
do i nope so i'm going to do it about my
form again
except for here i'm going to go to i
think it's
uh and i call it roadmap
if i go to roadmap it is uh no it's
roadmap
parent id parent name okay so now
i go to my roadmap annual goals
uh let's see edit roadmap
oh sorry for so annual goals will allow
me to return to annual goals
first quarter allows me return here but
now here
what i'm going to want to do on first
quarter
is i'm going to want that actually to
return to apparent so i'm going to
play around with this next time around
is i'm going to start working on
tweaking our query so we're only going
to show
parents and then within the parents
they're going to show
time frames that are child time frames
so we go to an edit time frame
we're going to see child time frames so
we're going to see goals for the period
and then child time frames so that take
care of us for now
we have once again run out of time as
you can see you can
start cranking through stuff but there's
a lot of little details we're gonna do
so
next time around we've set our task list
for that
time so until then have yourself a great
day a great week
and we will talk to you next time
you