📺 Develpreneur YouTube Episode

Video + transcript

Learn Python And Django Day 33

2021-02-18 •Youtube

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
0.63

[Music]

26.24

hello and welcome back

27.84

we're continuing our python and django

30.88

tutorials

32.079

and we're going to look at some

33.36

self-referencing models

35.28

and start building out a little bit of

36.719

structure within our roadmaps

38.32

and our goals first thing we want to do

42.079

is let's start with this we're from our

43.6

road maps we want to be able to come in

46.239

and within our time frames have some

49.12

structure so what i want to do is be

50.559

able to look at like overall annual

52.32

goals

52.96

and i want first quarter to actually

54.48

have annual goals as a

56.079

parent the way we do that is within the

59.28

model

60.32

so we can go back within here

64.559

and uh within time frame we had roadmap

68.08

as a parent but now what we get to do

70.32

is we're just going to call it parent

75.84

and this time we can just call it self

80.24

uh let's see and

85.119

like that and so we're gonna have a

87.36

parent

95.6

and it doesn't like that self

98.72

um so let's see we'll take a look at

100.479

that real quick

105.759

actually skip it i'm not going to dig

107.92

into self i'm going to just go

110

to uh time frame

113.6

so now it's parent is just going to be

114.88

another time frame it should

118.719

clean that up but okay we'll let it

120.24

clean it up in a minute

122.159

and so now that alone if you remember uh

125.52

if we look at our forms uh

128.879

time frame oh we we're gonna have to add

130.959

parent now

136.8

and let's put parent first just because

146.8

and we don't need to do anything special

148.56

with it

150.72

so we can go over here let's see i gotta

154

clean a few of these things up

157.36

let's close a couple of these out

161.12

let's take a look a bit we're running

163.599

time frame is not defined

167.92

let's take a look at that again i may

170.16

have to go back to that i may not be

171.519

able to do

172.239

time frame oh because it's not defined

174.64

yet

176.56

so i do need to use self

180.72

and i think i can do it this way let's

182

just check that real quick

184.959

itself is not fun so let's take a look

186.56

into that let's i'll go back over here

189.2

and it's

189.68

actually self it's a string

193.44

and i do want to grab this

199.44

because i need it as a parent i want it

201.44

to be able to be

203.2

uh null and blank oops i did not get the

205.76

e

206.319

so let's try that let's see what that

209.2

does for me

211.599

oh i forgot a comma so go back here

218.159

let's see if it picked it up it did uh

221.44

so i need to

222.56

whoops first thing i need to do is i'm

224.239

going to go over here

225.68

and i need to do my make migrations

230.4

and let's look at my model real quick so

232

i'm going to do time frames

233.92

but i also want uh okay tasks are tied

237.519

to a time frame so i'm good there so i

239.12

only need this one

240

done so i'm going to make migrations

244.239

now i'm going to migrate

253.519

and did that oh i need to run it i'll

255.84

get the server running again

258.799

and so now let's go back to my roadmaps

261.759

and now if i

262.72

edit annual goals

266.72

oh it did not come through i don't have

268.32

my form coming through

270

oh i'm sorry that's roadmap if i go to

272.639

first quarter

275.199

then i can set a parent uh it could be

277.84

itself which is going to be useless but

279.28

now i'm going to make it over all annual

280.56

goals

281.28

i'm going to save the record annual

283.68

goals does not have one

285.68

and so now let's go back to within road

288.96

maps

290.08

when i do edit a road map let's

293.12

adjust this so that it goes by parent

295.919

first

298.56

so that you go under your parent so if i

300.32

go to my view

302.96

where's my view there's my view

306.16

let's see actually first

309.68

my mistake let's go ahead and what we

312.16

want to do is here when we do first

313.68

quarter

315.44

we want to be able to within this

318.56

editing of tasks i want to be able to go

321.759

back to the quarter that we're working

323.039

with

323.759

so we want to go back to this time frame

327.36

so that's easy enough to do what we're

329.52

going to do is

330.479

whoops let's go back to where that was

331.919

viewed

334.08

so this was in our time frame and this

337.12

is an edit

338.08

listing there so if we go to our time

341.68

frame edit we can see here that we're

345.6

doing

346.32

uh we're doing that go page

349.84

so now if we do go page and we add

353.6

uh let's see we're just gonna do time

355.759

frame

356.96

equals uh

360.24

this is going to be

363.6

uh this guy which is

367.52

oh wait let's form his table we come

371.199

into there

372.72

is this the edit yeah it's time frame

374.479

edit

377.28

and so we're going to have to do

381.919

what did we call him let's go take a

383.759

look at him i think we called him

385.919

something let's see so if we go to time

387.68

frame edit time frame edit edit time

390.24

frame

390.88

let's come in here time frame

396.88

and we've got a form but let's just go

398.479

ahead and do

400.4

this to make it easy

403.6

tfid and that is going to be

408.08

equal to

412.319

uh here which is an id

415.759

so we're just going to send tfid in

418.8

we got that and so now we can go to our

421.28

edit

422.639

and he's going to be tfid just keep it

425.68

simple

427.199

so now what we're going to do is we're

428.56

going to see that this is going to come

430.4

across

432.24

let's just reset this one and so now

435.28

when i do an

436

edit i can see that

439.039

i added this time frame id but that's

440.88

not i'm not doing anything with it so

442.8

now

444.319

when i go to my edit for a task

450.4

uh edit task is in here somewhere

454.4

there we go so what i can do here

457.599

is i can set

461.84

uh let's keep it pretty simple is i'm

463.919

going to add a parameter

465.84

which is a parent

470.08

uh we'll just keep it parent right now

473.199

i'm not going to call it an id

474.72

yeah let's do it that way let's just

475.919

keep it simple parent id we're going to

477.199

call it pid

479.28

and now what we can do is we can do

480.639

request

482.879

dot get

488.479

and then we're going to do tf which is

491.68

what we called it so actually let's just

493.12

print it for now

498

because there's actually two things

499.12

we're going to do because we're going to

500

do pid here

502.479

so we did this big if here now we've got

504.96

to do

505.52

an else because we have to handle the

507.12

two so here

510.24

print

514.159

he's going to print it as a git he's

516.24

going to print it as a

517.76

post although i don't think we'll ever

520.719

actually post but that's okay

526

actually we'll probably just carry it

527.04

across so we'll just keep it for now so

528.56

let's just do it through this

530.399

and so now we're going to do a print

532.88

just to test it save it

534.64

come in here and actually we can run

537.44

this

538.959

and if we go back and look we're gonna

540.72

see in our output

544.399

two there we go so we printed out r2 we

547.12

can see here that's our get

548.72

so now

552

with that let's

555.12

just

559.2

let's play with this a little bit so

561.04

here else

564.64

and we're going to say uh parent id oops

568.72

parent id equals this and we're going to

571.519

do it as a string because i don't think

573.04

we really

573.68

care too well we're going to send both

578.08

so let's do that

581.68

because we're going to work with this a

583.04

little bit

586.64

let me do this so a parent

592

we're going to default it to nothing

595.519

but here

602.839

if

605.44

if we have that

608.72

then we're going to do the uh

612.56

because that's going to be parents so

613.6

parent id equals and we're going to make

616.16

it an

616.839

int request.get

622.48

and then we need to do a

625.519

then parent is going to be equal to time

627.839

frame

630.56

dot objects dot get primary key

634.88

equals the pid

638.32

we do the same thing here for post

642

uh params we're gonna add a parent

646.399

and this can be equal to parent which

647.839

may be a null oops i don't need that

650.64

which may be a null or it may be a value

660.56

not going to play with the post yet

662.48

because we may

664

be able to deal with that later we'll

665.839

leave it for now uh so that gives us a

667.839

parent so that means now that we can

669.36

address the parent within the

671.44

time frame editor

675.12

and we're going to create a button here

678.079

that says

681.279

create task break break break break so

683.04

let's go here

686.48

i'm going to do so we're gonna if

689.6

parent

696.88

i need to end if

702.64

so if i have a parent then i'm going to

705.04

add another button

708.399

and this one's going to be

712.72

return to

716.72

and we're going to do parent.name

719.2

because that's what we called it

721.2

otherwise he's going to go to time

724.56

frame

727.6

parent id

733.279

so let's see how that works out

738.16

so now let's go to our row actually go

739.92

to a time frame first quarter

743.279

if i edit this one it should be

747.2

uh please update record

752

and he's not giving me that yet so let's

754.24

see that's task time frame 2.0 let's go

756.8

take a look at that real quick

758.24

it's not 2.0 but 2-0 let's see what it

760.24

said

762.639

uh let's make sure it's getting the

764.56

right oh it's not a time frame

766.24

my mistake it's not the time frame it is

770.639

so i have a time frame too uh it is the

776.48

oh it is time frame okay so let's go

778.88

back and look at this real quick

780.72

so i do edit task

783.92

edit task

787.68

parent equals that that's parent

794.56

so let's just do this let's print

800.16

that

804.88

now let's prepare it oops

812

and print the parent

817.76

so went to task edit was i looking at

819.6

task in it

822.72

oops that was in time frame edit instead

825.36

task edit okay my mistake

827.519

uh let's get rid of that

832

and i don't think i had parent anywhere

834.56

else

836.8

okay so i should go instead of time

838.48

frame edit let's go to task edit

844.8

and here uh let's just do it above the

847.36

form

849.279

so if parent i'm gonna put a little

850.72

button here

852.32

and i don't need that so now

856.639

i take a look turn the first quarter

860.399

and now i go back and i can see that so

862.72

if i do that

864

let's go back to my road maps annual

866

goals

867.519

if i go to overall annual goals

870.88

then this one's returned to overall

872.56

annual goals so now what i want to do is

874.32

say

874.639

the same thing and i'm going to do a

876.079

parent for the time frame

879.36

so here

884.16

and it's going to get sort of

885.04

complicated because what we're going to

887.04

end up doing is we're going to have to

888.56

sort of

889.04

take that extra value across

893.6

so we're going to do

897.04

uh within roadmap so let's go back to

900.24

roadmap

901.04

so when it doesn't edit here on the

903.12

roadmap i want to add

905.279

a roadmap id which is going to be rm so

907.279

if i go to roadmap

910.839

edit

913.36

it's going to go to a time frame and i'm

915.44

going to give it roadmap

916.88

equals

920.399

which is going to be this guy so

924.839

rmid and i'm going to do it basically

926.8

the same way

927.92

here so that means when i go to

932.32

roadmap edit in my views

940.399

roadmap create edit

945.44

and then here

950.72

i'm going to send my current rom id and

952.72

i could do this a little differently but

953.92

i'm just going to do it this way it's a

955.04

little easier that way

958

i'm going to come in and do that is

960

equal to

962.079

id that's right because i've already

963.519

passed in so i'm just going to pass it

964.72

through

967.12

and so now when i do edit

970.16

time frame

974.399

uh let's see where actually let's take

977.6

my i'm going to steal my edit task stuff

979.519

real quick

981.519

i'm going to take this

985.279

well let's not worry about the parent

986.399

part let's just do this if requests get

988.88

let's do that

992.88

and now oh i'm going to get rid of my

994.24

prints because i don't need those

997.04

i have a second print i did have another

998.399

print there

1000.32

let's go to edit time frame

1003.92

and then here pop up

1010.639

so here's my else if i'm a post

1012.48

otherwise i'm gonna do it but now it's

1013.92

not

1014.399

tf it's rem whoops

1018.72

rm

1021.759

rm and that's not a time frame that's a

1024.64

road map

1028.079

uh parent id by a bam i don't need to

1030.4

print that

1032.16

i do need this to be parent

1039.039

and i want to do a parent here equals to

1042.16

null

1047.039

and i don't need that print but i do

1049.039

need this

1051.12

to be a post

1060.24

and now let's steal from my task edit

1062.4

where i did my parents

1063.76

i'm going to do the same thing i'm going

1065.2

to put that on my time frame

1068.96

and let's see i don't have any real

1070.64

buttons up there

1073.84

do i nope so i'm going to do it about my

1075.52

form again

1078.16

except for here i'm going to go to i

1080.559

think it's

1081.44

uh and i call it roadmap

1085.919

if i go to roadmap it is uh no it's

1088.96

roadmap

1093.52

parent id parent name okay so now

1098.08

i go to my roadmap annual goals

1101.6

uh let's see edit roadmap

1105.52

oh sorry for so annual goals will allow

1108.64

me to return to annual goals

1110.32

first quarter allows me return here but

1112.64

now here

1113.36

what i'm going to want to do on first

1115.039

quarter

1116.4

is i'm going to want that actually to

1117.76

return to apparent so i'm going to

1119.679

play around with this next time around

1122.08

is i'm going to start working on

1124.08

tweaking our query so we're only going

1126.24

to show

1127.12

parents and then within the parents

1128.96

they're going to show

1130.96

time frames that are child time frames

1132.88

so we go to an edit time frame

1136.16

we're going to see child time frames so

1139.36

we're going to see goals for the period

1141.12

and then child time frames so that take

1143.44

care of us for now

1144.72

we have once again run out of time as

1147.039

you can see you can

1148.16

start cranking through stuff but there's

1150.08

a lot of little details we're gonna do

1151.76

so

1152.24

next time around we've set our task list

1154.72

for that

1155.36

time so until then have yourself a great

1158.16

day a great week

1159.36

and we will talk to you next time

1177.84

you