📺 Develpreneur YouTube Episode

Video + transcript

Learn Python And Django Day 37

2021-03-04 •Youtube

Detailed Notes

Part 2 of our look at using session variables for passing data.

You can view source for today and all prior days by reviewing the tag Day 37 at this GitHub: https://github.com/robbroadhead/develpreneur-pythontutorial

Transcript Text
[Music]
well hello and welcome back
we are going to continue sort of like a
part two as we're looking at pulling
some of our values into sessions
and we're gonna track our current time
frame at this point
so as we go into edit one if we do
return our annual goals
there we go i don't know why that's
popping up
when we do an edit here we're going to
come in
and we want to make sure that we're
going to set our current one but also
be able to pick up a parent if there is
one so we have a couple things we need
to do
and first thing we want to do is we've
got our p
that we is our variable we just kept it
very simple
uh somewhere in here let's do it this
way
i think we did it like that oh maybe
it's nice and it was probably single
quotes around it
there we go so we were just going to set
that so when we come in and do edit task
then uh we're going to set the parent
but the first thing we need to do now in
this case
this is so we've got an id so we're
editing once we already have
potentially a parent
and so what we need to do actually here
is say either actually i guess what we
do is we just set our parents
which we're going to do here and let's
check our parent
so we're going to come through all of
this let's see and we're going to
actually do
here see did i use that already
just in case yes i did
so when i create a time frame
i'm gonna go see if the parents out
there let's see data's time frame blah
blah blah blah okay so this isn't
creating so i can get
set my parent in this case now the edit
is a little different because in here
what i want to do is i'm going to
uh let's see so i set my roadmap but i
also need to set my parents
if i have a parent if i don't have a
parent
then it's going to be me
and actually when i come out of this
it needs to be me anyway so what i need
to do here
uh well this is the check what i do need
to do right before i
jump to my screen
is i need to do the request whoops
request dot session
p is actually going to be equal to
my id and we're doing this as an id so
it's going to be
uh let's see so here it's edit so i'm
just going to make it equal to this id
so i need to make sure that i'm going to
check it i need to check it beforehand
and i do that
let's see so as i come in i'm going to
edit and well in this case i'm actually
in pretty good shape because what i'm
going to do is i'm going to say that
i'm i'm gonna grab the data for that guy
and
i'm actually in pretty good shape
because i've already grabbed the data uh
parent where did i set parent parent
parent parent parent
parent equals data dot parent so then
edit i'm okay in a create let's make
sure i got that
creating a time frame
then i'm going to try to grab the parent
if i can
and i don't need to actually
set it at this point um
because it would have been from an edit
and then the parent is
going to be there so i should be okay so
let's check that oh and then
actually while we're at it uh when we do
an edit time
frame i'm sorry edit task
where's our tasks there's active edit a
road map
create a road map list a road map oh and
actually we need to
we need to free this up so when we
select a new roadmap
we just need to make sure uh
let's just put it and we'll put it up
here
uh here what we need to do is
request.session
p equals none because we'll make sure we
jump to a new time
frame i'm sorry a new roadmap that we
clean out the time frame parents because
now
roadmap is our our top level our route
of
our path that we need to follow down
sort of our cookie trail
let's see creating a road map we can
actually probably create road map let's
just do it just to be safe we're going
to do the same
and actually when we do create roadmap
right now we're going to come in and
that's one of the first things we're
going to do is we're going to clean
those two
out
which again i probably should call this
like uh
let's do it that way let's do uh
clean session
and uh that has to have the request
and we're just gonna do it like that
so we're gonna do clean session
request whoops let me do that
so we'll probably use that in a couple
places uh so now let's jump back to our
parent we're gonna steal that code
and when we do an edit task
giving a little vamping a little bit in
our edit task okay so an edit task
we come in uh let's see so editing a
task we should be in pretty good shape
prints null but if
actually that should be parent equals
none let's do that
and actually here because we're doing
this so parent actually equals
as we come in it's going to be the
object because we're getting a task
object so it's going to be data dot
i would call that time frame oh this is
actually a parent for a task let's look
at that did we do it that way
uh we did not we don't have stack tasks
they're tasks they are
all attached to a singular
frame so okay so we're good there so our
parent is actually
in this case is our time frame
and then if we come through here this is
where
we handle if uh let's see so if it's a
post
then we do some stuff but if not and so
this is where we can just
say here is if there's a parent in the
session
then we're gonna get that uh
let's see if he's there then we're gonna
grab that parent and we're gonna set him
there
and so now we don't need to do this
because this is where we're checking our
um query string variables we don't need
those two
let's make sure we got that right let's
press it okay so we should be good there
so that's in editing a task we may need
it let's see if we go to create
task
um i'm gonna get rid of that test i
don't think i use that anymore did i
clean that up somewhere
i did not let's get rid of that just to
get that out of there
clean that thing up and let's see
deleting a task
create a task here we go so here we were
not
in creating a task we don't send
anything in but now what we can do
is let's see we get it this is a new one
so if it's in request session then
uh data dot time frame
equals parent then actually just call it
that let's say it's going to be tf
tf and so now when we create one if
there's one in the session we're going
to create it based off of that
oh we're going to save that there we go
because it was barking about it
and i think we are in good shape
in that so now we should be set that we
could start all the way up in our road
map
and uh let's see so this is annual goals
2021
and now we've got personal goals and
professional goals
and um this is going to be just like
we'll do delete
goals we're going to create one here but
it's looking for
time frame matching the query so i think
when i do this creating a time frame
so it should be tf
which is interesting why it is not
so let's take a look at that real quick
so if we do the time frame
without anything so that calls create
time frame
time frame there we go
uh that's id we should be good there we
should be good there
let's see let's go look at that oh where
did that go let's go look at that error
a little more specifically
so he's in 296.
is right here
so if he's in the session oh
what we need to do is if
uh not equal to none
then we do that probably have to change
that a couple places
and so let's check that real quick let's
go back here
let's uh reload that page and now if we
do create time frame so now we've got
that
uh it's got a road map it has no parent
but let's go back and
let's go to our personal goals
and so let's look at this one real quick
is we have no parent because it doesn't
have a
parent time frame
we can uh create a let's create a goal
for the period oh we gotta
clean that up a little bit but let's
create a task
so let's do so this is an annual goal
for personal
and let's just create a task
and we should see but we're not seeing
it because we didn't get our
our time frame didn't get set
as we came through for creating a new
uh task so let's take a look at that
when we create a task that is the task
so we're walking our way through these
guys so let's create tasks
if we go here
create task there we go so if p
is in the session then it should say
uh data.timeframe equals that
let's make sure that we change that
somewhere oh i don't think we did
because i think if we do task
edit uh let's see go
page parent id
uh let's go back we may have switched
that up a little bit so
here
oh we don't have one on the
create task so if we go to edit task we
probably see that same thing where we
have a parent
and let's see so we pulled it from the
time frame
so in create task what we need to do is
we've got a parent
whoops
and he's going to be parent but we need
to come here
and either say
let's do it this way so parent is either
no
so let's just do parent well let's do
this
yeah we'll do it this way so parent
equals a time frame
and then here uh let's see
we can just do parent
equals tf
so if we do that and then we come back
here
and we do our create task now we should
see
it's still not coming through
okay so i'm on a time frame so i should
see
my time frame so and then when i do
create tasks let's take a look at whoops
let's take a look at that real quick
so create task let's look at this real
quick
print
request dot session
take a look that real quick as we do a
create
now when we look
uh he does that
let's do my parent um
print whoops
print parent and let's just see what he
looks like because he says here i'm
gonna set my parent otherwise i'll go
through here
all right let's try this guy real quick
back through this because this we're
gonna make this a three-parter
now whoops go back here because i want
to look over here
and uh so parent is annual personal
goals
which is my time frame and so he should
be picking that up but he is not so i
may not have that in my
edit task let's see
if i go task edit and i think that's the
only one i've got
if i set here she should all be
good oh i may not be setting my let's
make sure i'm setting my
form properly so oh i bet i'm not
let's see so here's my form
uh oh so what i want to do is actually
let's break him down
here let's bring him further down where
i actually load that up
probably not load my values right
and so now there we go so now i can
create a task i've got this
and this is just going to be delete me
well actually i don't even have to do
that
and so if i create a goal for a period
if i go to second
like a first quarter i'm gonna have um
oh if i create a time frame then my
parents okay
if i go into a time frame like my first
quarter goals
if i create a task then it's for the
time frame of first quarter
if i create a time frame my parent is
first quarter
and so there we go we've got those now
we do
have um i think we're actually in pretty
good shape because we can do
we want to change our task list but now
we've got a very basic
version of this we did have
a listing of tasks in general
that we're going to want to deal with
i'm sorry that's not there that's in our
url
so we have this tasks which we actually
no longer have
access to
we may want to clean that up because now
it shows
all of our tasks and actually i'm sorry
time frames
is the other one that shows all time
frames and we may want to change that up
but for right now i think that gives us
a our basic
flowing through our application we're
going to continue we're going to do some
cleanup
and we're actually getting pretty darn
close to something we can use here
and we'll take care of that next time
around so go out there
have yourself a great day and we will
talk to you
next time
you
Transcript Segments
0.62

[Music]

26.72

well hello and welcome back

28.4

we are going to continue sort of like a

31.119

part two as we're looking at pulling

32.559

some of our values into sessions

34.96

and we're gonna track our current time

37.44

frame at this point

39.12

so as we go into edit one if we do

41.84

return our annual goals

43.52

there we go i don't know why that's

46.16

popping up

48.32

when we do an edit here we're going to

51.12

come in

51.68

and we want to make sure that we're

52.8

going to set our current one but also

55.36

be able to pick up a parent if there is

57.12

one so we have a couple things we need

58.48

to do

61.199

and first thing we want to do is we've

63.199

got our p

64.479

that we is our variable we just kept it

66.56

very simple

68.64

uh somewhere in here let's do it this

71.6

way

73.28

i think we did it like that oh maybe

75.68

it's nice and it was probably single

76.96

quotes around it

78.479

there we go so we were just going to set

80.56

that so when we come in and do edit task

84.84

then uh we're going to set the parent

87.119

but the first thing we need to do now in

88.56

this case

90.079

this is so we've got an id so we're

91.759

editing once we already have

93.6

potentially a parent

97.119

and so what we need to do actually here

100.24

is say either actually i guess what we

103.439

do is we just set our parents

105.04

which we're going to do here and let's

108.159

check our parent

112.159

so we're going to come through all of

113.84

this let's see and we're going to

115.52

actually do

116.24

here see did i use that already

120.32

just in case yes i did

124.96

so when i create a time frame

128.8

i'm gonna go see if the parents out

130.8

there let's see data's time frame blah

132.56

blah blah blah okay so this isn't

133.68

creating so i can get

134.72

set my parent in this case now the edit

137.28

is a little different because in here

139.44

what i want to do is i'm going to

144.56

uh let's see so i set my roadmap but i

147.28

also need to set my parents

150

if i have a parent if i don't have a

152.56

parent

153.68

then it's going to be me

157.04

and actually when i come out of this

160.4

it needs to be me anyway so what i need

162.239

to do here

165.519

uh well this is the check what i do need

167.68

to do right before i

169.04

jump to my screen

172.08

is i need to do the request whoops

176.56

request dot session

181.2

p is actually going to be equal to

184.239

my id and we're doing this as an id so

188.48

it's going to be

190.239

uh let's see so here it's edit so i'm

192.72

just going to make it equal to this id

195.36

so i need to make sure that i'm going to

196.959

check it i need to check it beforehand

200.239

and i do that

203.519

let's see so as i come in i'm going to

205.28

edit and well in this case i'm actually

207.04

in pretty good shape because what i'm

208.159

going to do is i'm going to say that

211.599

i'm i'm gonna grab the data for that guy

214.48

and

215.44

i'm actually in pretty good shape

216.48

because i've already grabbed the data uh

218.48

parent where did i set parent parent

220.72

parent parent parent

221.76

parent equals data dot parent so then

223.36

edit i'm okay in a create let's make

226.159

sure i got that

227.84

creating a time frame

230.879

then i'm going to try to grab the parent

233.519

if i can

234.959

and i don't need to actually

238.319

set it at this point um

243.2

because it would have been from an edit

244.959

and then the parent is

246.239

going to be there so i should be okay so

249.36

let's check that oh and then

250.56

actually while we're at it uh when we do

253.12

an edit time

254

frame i'm sorry edit task

259.12

where's our tasks there's active edit a

262.4

road map

263.68

create a road map list a road map oh and

266.32

actually we need to

267.68

we need to free this up so when we

269.28

select a new roadmap

272.32

we just need to make sure uh

275.759

let's just put it and we'll put it up

278.479

here

279.199

uh here what we need to do is

281.32

request.session

285.28

p equals none because we'll make sure we

288.479

jump to a new time

289.44

frame i'm sorry a new roadmap that we

291.919

clean out the time frame parents because

293.52

now

294

roadmap is our our top level our route

297.28

of

297.6

our path that we need to follow down

299.199

sort of our cookie trail

302.88

let's see creating a road map we can

305.44

actually probably create road map let's

306.8

just do it just to be safe we're going

308

to do the same

310.24

and actually when we do create roadmap

315.36

right now we're going to come in and

316.4

that's one of the first things we're

317.199

going to do is we're going to clean

318.32

those two

319.199

out

322.72

which again i probably should call this

324.24

like uh

326.479

let's do it that way let's do uh

330.32

clean session

334

and uh that has to have the request

341.44

and we're just gonna do it like that

346.96

so we're gonna do clean session

351.199

request whoops let me do that

354.96

so we'll probably use that in a couple

356.24

places uh so now let's jump back to our

359.039

parent we're gonna steal that code

365.039

and when we do an edit task

370

giving a little vamping a little bit in

372.319

our edit task okay so an edit task

375.12

we come in uh let's see so editing a

378.72

task we should be in pretty good shape

380.639

prints null but if

388.08

actually that should be parent equals

389.52

none let's do that

397.12

and actually here because we're doing

398.479

this so parent actually equals

401.919

as we come in it's going to be the

404.16

object because we're getting a task

405.36

object so it's going to be data dot

407.52

i would call that time frame oh this is

410.8

actually a parent for a task let's look

412.4

at that did we do it that way

415.84

uh we did not we don't have stack tasks

417.599

they're tasks they are

418.96

all attached to a singular

422.16

frame so okay so we're good there so our

424.4

parent is actually

425.599

in this case is our time frame

430.08

and then if we come through here this is

432.639

where

433.919

we handle if uh let's see so if it's a

436.88

post

437.759

then we do some stuff but if not and so

440.88

this is where we can just

443.44

say here is if there's a parent in the

445.28

session

447.44

then we're gonna get that uh

452.88

let's see if he's there then we're gonna

454.16

grab that parent and we're gonna set him

456.639

there

459.919

and so now we don't need to do this

462.72

because this is where we're checking our

464.4

um query string variables we don't need

467.039

those two

469.52

let's make sure we got that right let's

471.36

press it okay so we should be good there

474.639

so that's in editing a task we may need

477.12

it let's see if we go to create

478.56

task

481.759

um i'm gonna get rid of that test i

483.52

don't think i use that anymore did i

484.879

clean that up somewhere

488.16

i did not let's get rid of that just to

489.84

get that out of there

497.52

clean that thing up and let's see

500.72

deleting a task

502.8

create a task here we go so here we were

506.16

not

506.879

in creating a task we don't send

510.72

anything in but now what we can do

514.56

is let's see we get it this is a new one

518.88

so if it's in request session then

522.08

uh data dot time frame

527.12

equals parent then actually just call it

529.92

that let's say it's going to be tf

533.519

tf and so now when we create one if

537.839

there's one in the session we're going

538.959

to create it based off of that

543.2

oh we're going to save that there we go

545.68

because it was barking about it

547.68

and i think we are in good shape

551.36

in that so now we should be set that we

554.72

could start all the way up in our road

556.24

map

557.2

and uh let's see so this is annual goals

560.839

2021

562.08

and now we've got personal goals and

563.519

professional goals

565.6

and um this is going to be just like

569.2

we'll do delete

570

goals we're going to create one here but

572.48

it's looking for

575.12

time frame matching the query so i think

581.519

when i do this creating a time frame

586.64

so it should be tf

591.04

which is interesting why it is not

600.399

so let's take a look at that real quick

602.24

so if we do the time frame

604.16

without anything so that calls create

606.32

time frame

610.24

time frame there we go

615.279

uh that's id we should be good there we

617.519

should be good there

623.68

let's see let's go look at that oh where

625.519

did that go let's go look at that error

626.88

a little more specifically

629.04

so he's in 296.

632.079

is right here

635.6

so if he's in the session oh

639.44

what we need to do is if

646.24

uh not equal to none

651.519

then we do that probably have to change

654.24

that a couple places

659.68

and so let's check that real quick let's

661.68

go back here

663.839

let's uh reload that page and now if we

666.8

do create time frame so now we've got

668.72

that

669.839

uh it's got a road map it has no parent

674.399

but let's go back and

677.68

let's go to our personal goals

681.279

and so let's look at this one real quick

682.8

is we have no parent because it doesn't

684.72

have a

685.36

parent time frame

688.64

we can uh create a let's create a goal

691.519

for the period oh we gotta

692.88

clean that up a little bit but let's

694

create a task

696.56

so let's do so this is an annual goal

700.72

for personal

704.079

and let's just create a task

707.6

and we should see but we're not seeing

709.36

it because we didn't get our

711.44

our time frame didn't get set

714.56

as we came through for creating a new

718.16

uh task so let's take a look at that

720.88

when we create a task that is the task

725.12

so we're walking our way through these

726.32

guys so let's create tasks

729.76

if we go here

733.279

create task there we go so if p

736.32

is in the session then it should say

740.32

uh data.timeframe equals that

744.72

let's make sure that we change that

746.079

somewhere oh i don't think we did

748.079

because i think if we do task

749.2

edit uh let's see go

752.399

page parent id

757.6

uh let's go back we may have switched

759.92

that up a little bit so

761.36

here

765.44

oh we don't have one on the

769.279

create task so if we go to edit task we

771.68

probably see that same thing where we

772.8

have a parent

776.079

and let's see so we pulled it from the

781.12

time frame

784.24

so in create task what we need to do is

787.2

we've got a parent

792.8

whoops

797.6

and he's going to be parent but we need

798.959

to come here

800.72

and either say

804.16

let's do it this way so parent is either

807.04

no

807.76

so let's just do parent well let's do

810.88

this

812.079

yeah we'll do it this way so parent

814.24

equals a time frame

818.079

and then here uh let's see

821.839

we can just do parent

824.88

equals tf

828.32

so if we do that and then we come back

831.199

here

832.8

and we do our create task now we should

835.12

see

836.24

it's still not coming through

841.519

okay so i'm on a time frame so i should

843.839

see

844.639

my time frame so and then when i do

847.12

create tasks let's take a look at whoops

848.8

let's take a look at that real quick

852.88

so create task let's look at this real

855.68

quick

856.48

print

862.44

request dot session

868.16

take a look that real quick as we do a

870.24

create

871.76

now when we look

875.279

uh he does that

879.519

let's do my parent um

884.72

print whoops

888.56

print parent and let's just see what he

892.079

looks like because he says here i'm

893.839

gonna set my parent otherwise i'll go

895.12

through here

896

all right let's try this guy real quick

899.519

back through this because this we're

901.68

gonna make this a three-parter

904.32

now whoops go back here because i want

905.92

to look over here

908.16

and uh so parent is annual personal

910.839

goals

914.16

which is my time frame and so he should

917.68

be picking that up but he is not so i

919.36

may not have that in my

920.8

edit task let's see

923.92

if i go task edit and i think that's the

927.199

only one i've got

929.6

if i set here she should all be

933.44

good oh i may not be setting my let's

936.639

make sure i'm setting my

937.68

form properly so oh i bet i'm not

941.279

let's see so here's my form

946.24

uh oh so what i want to do is actually

948.079

let's break him down

949.44

here let's bring him further down where

952.079

i actually load that up

956.8

probably not load my values right

960

and so now there we go so now i can

962.24

create a task i've got this

964.48

and this is just going to be delete me

967.68

well actually i don't even have to do

968.8

that

970.72

and so if i create a goal for a period

972.8

if i go to second

974.399

like a first quarter i'm gonna have um

977.6

oh if i create a time frame then my

980.959

parents okay

982.48

if i go into a time frame like my first

985.279

quarter goals

987.759

if i create a task then it's for the

990.639

time frame of first quarter

992.56

if i create a time frame my parent is

994.639

first quarter

996.639

and so there we go we've got those now

999.199

we do

999.68

have um i think we're actually in pretty

1002.8

good shape because we can do

1004.56

we want to change our task list but now

1006.639

we've got a very basic

1008.48

version of this we did have

1011.759

a listing of tasks in general

1015.44

that we're going to want to deal with

1017.519

i'm sorry that's not there that's in our

1018.959

url

1020.16

so we have this tasks which we actually

1022.639

no longer have

1023.519

access to

1026.559

we may want to clean that up because now

1029.199

it shows

1029.839

all of our tasks and actually i'm sorry

1031.839

time frames

1033.36

is the other one that shows all time

1036.16

frames and we may want to change that up

1038.64

but for right now i think that gives us

1039.919

a our basic

1042

flowing through our application we're

1043.52

going to continue we're going to do some

1044.799

cleanup

1046.16

and we're actually getting pretty darn

1047.919

close to something we can use here

1049.84

and we'll take care of that next time

1051.28

around so go out there

1053.76

have yourself a great day and we will

1056.4

talk to you

1057.6

next time

1075.12

you