📺 Develpreneur YouTube Episode

Video + transcript

Learn Python And Django Day 36

2021-03-02 •Youtube

Detailed Notes

This lesson takes a look at using session variables instead of query parameters for storing and passing values.

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

Transcript Text
[Music]
well hello and welcome back
we are going to clean up a little bit
we're continuing to look at
some sort of the background data that we
want to track
uh lately we've been working our way
into passing values in so as we
uh go in here we added a road map
and then we for example want to create a
new time frame then we are
pre-populating
our our road map but we're doing it here
by sending variables in and we're going
to do i'm going to take a look at
another approach to doing this which is
um probably cleaner to some extent but
it does have some
some issues that you can run into based
on
browser but at least wanted to touch on
it and that's the idea of putting stuff
into the session
and the way we're going to do this is
we're going to uh whoops let me jump
over here
when we select a roadmap
then we're going to set a session value
of our current
id and what we're going to do there
is and it's not too complicated to do so
we've got
let's look at roadmap so we list
we can either create one or we can edit
one
now creating one is we're going to need
the id
of what we built and when we create one
we actually
ended up let's go look at this real
quick because i don't think we need it
so if we come here and create a new road
map i'm going to do let's do annual
goals
2022 get ahead of ourselves a little bit
and save a record and so here it's going
to bring us back here so
we don't really have to worry about it
on the create we're just going to do it
on the edit
which is awesome because we know exactly
what the idea is we don't have to do
something where we um insert a record
and then get the returned id
we actually have this so we go into edit
roadmap
because they're going to click here and
they give us an id so all we're going to
do is right away say if they're
authenticated then we can actually do
something here
and we're going to just say request
whoops if i can spell it right
dot session and we're going to call
this uh we'll just call it rmid
equals id so now we have set
a session variable and what we can do
is uh here when we do edit
and then for example create before we
were tacking in
attacking on the rd the id we don't need
to do that anymore so when we go
to roadmap edit
and we go here we're creating this
uh rm equals arm id and i'm going to
actually get rid of that
so now we're just going to create a time
frame
and when we do create time frame which
is tf which let's make sure i got that
right that goes to create time frame
great time frame there we go so we want
to do here
is we're looking for it in the request
now we're going to look for it in the
session
and we're really only going to change
this a little bit is we're just going to
say request.session
and we called it uh rmid
and we do it like that so now we're
going to check that within the session
now there's some things we could do
um we could create like a
essentially a function that checks a
session and pulls some values in
um but we're just going to keep this as
part of
so we could we could take these little
things and bundle this text up
and do it as part of something we return
back um
you know do these checkings and settings
but we're not going to bother with that
right now we're just going to keep it
very simple inline code
there will be some duplication so we'll
look at like create time frame
and there will probably be let's see if
we do like an edit time frame
edit time frame
oh well i guess in that case we don't
have to worry about it in the edit time
frame
um well we did do it here
so let's change that up
so here we said if it was in the session
uh that's going to be
well what did we have before let's take
a look at that real quick before
oh which is actually a problem there
because we have we were checking in the
get
but it actually should have been in the
post
so called a bug there um that should be
in the post
oh because we pass a road map in so here
we can do
actually this is in both of these so
we're going to do a request dot session
and we're gonna do we gotta clean this
up a little bit so if rmid
and request.session
actually is that the same thing then we
can take that
oh so let's go back to that was at the
bottom
so if we go here i think that was at the
bottom
yeah here we go
so let's just go ahead and sort of steal
that code and clean that up so else this
was if
let's see if
he's there but here he's going to do the
well we can just do this we want to call
him roadmap
uh rmid equals that okay and then here
we can do the same if he's in the co and
actually now we don't have to check
whether it's in the post
or the um the get
now we can just simply come through here
and say regardless we're going to say if
it's in the session
then we're going to go ahead and pull
that thing out
so that gives us for uh editing
so now
and we can probably find so that was
within
well we're probably in pretty good shape
so if we go to here if we go to
i think we're probably good let's see
i'll go test it out so now let's go
and if we edit
let's go edit here and this is our
overall
annual goals let's edit this and let's
say
overall let's see personal
we do personal goals
and it's an annual so we're going to
save that record
and oh that's interesting we ended up
posting here so now it's
so annual goals here if we look here
oh we didn't say oh oh i'm sorry because
this is a road map and then we go to
personal goals and we go here
and let's see does this return to 2021
it does
oh let's take a look at that link real
quick
make sure that we've got yep we're not
setting it up there
if we do create time frame are we
sending it here
we are so if we look at uh this is
time frame with child oh because that's
the oh that is the road map so
let's fix that one i thought we had that
somewhere else so let's go here
and we do edit time frame uh we had that
i think we also need a we had another
create time frame
let's edit did we call it yeah here it
is
down here at the bottom create time
frame
we oh we've got that one fixed
so okay so we're probably all right
we can go to the time frame i believe
it's time frame edit and we don't
have to send the roadmap
anymore and we also had it here
so we don't have to do it as
a part of the edit so let's make sure we
got both of those i think we did
so there's create time frame and edit
time frame
and that's where we clean that up so we
should be good there
so we've got personal goals and let's go
back up here and let's create
um
oh this is gonna be uh annual
personal goals and he doesn't have a
time frame parent uh we're gonna save
the record
and then um oh we got to clean this one
up
so when we do a oh this is all time
frames
so let's take it we'll take a look at
that in a second well not in a second
but
we'll take a look at a little bit later
so now let's go back to our roadmap
uh we have our personal goals we're
going to create a tank time frame
which is going to be uh
professional goals
and we'll call it annual professional
goals well we'll just keep
that because it is an annual time frame
we've got a road map
we're gonna save a record and
uh we can create a time frame here so
let's do that oh
so here we go id expected so here where
we do this p
we're not getting something back so
let's take a look at that
let's back it up so when we do create
time frame of this one
let's take a look at this guy so this
guy
is over here he doesn't have anything if
we go to edit professional goals
and do create a child time frame
uh let's see so one i'm still saying
this rm equals one so we've got to fix
that
so that was in
edit i guess
yes so editing a road map is still got a
bad a link that we don't need
let's see here
so we don't need that anymore
and then we went to edit professional
goals
create time frame i think this one that
broke oh no it didn't
so why was the p oh i think when we
created we were not
properly filling this out so that's what
we need to do and so that's a little bug
that we'll fix
we'll come into that next time actually
because what we'll do is when we create
a new
time frame we can't immediately do this
create time frame
so we need to have something where it
doesn't display this until
we have a a time frame id if we're
creating a new one
then we don't have the values because
here this create time frame
is actually filling this out and
actually what we're going to do is we're
going to correct that
as well so everywhere we have this
p we're going to also have
so we have uh create a time frame record
here so this is going to be
uh where we have this we're actually
going to be let's call this we're just
going to do it
tfid
i assume that is the oh that's the
parent
so let's do that we'll keep it there um
we'll call it p
we'll keep it that way so parent is
question
session uh if he is in that
request.session then we're gonna do
request.session
p and then dated.parents so we need to
find where we were using
parent
oops let's do it that way and let's see
so here it was in the post of a time
frame
and so let's see if request.pose time
frame which was going to be the parent
so this is an editing okay so
well we want to tweak this a little bit
so when we come into a task
editing a task
then a parent is here but what we need
to do
is say as we get through
so if we get a if we get one then we
need to do
the uh question.session
whoops
i need to set its parent
is going to be equal to oh i'm sorry it
was a p
is going to be data
dot
uh where did i set that where did i set
that data dot
parent i think it's just data apparent
so let's do that
oh but it's not oh it's not it's called
it's going to be actually data. time
frame we'll take a look at that guy real
quick
and so here we're going to have to
finish this one up next time so that's a
time frame period but a task
has a yes is a time frame
so we get down to here we need to set
here it's going to be his
so that'll be the parent that's like
basically the time frame where we're
currently in
and we're going to this is going to get
a little more complicated because we
could have
uh essentially a task a a
series of these going in so i think what
i want to do is wait and tackle that
next time around so hold that thought
and we will uh we'll come back in our
next episode and we're going to continue
working on this and this is going to be
two things we're going to look at our
time frames being able to access a
current parent
and then with the tasks making sure that
we're updating that parent as we go
which again
is where the session management of stuff
can get a little bit
complicated but that being said i'll let
you get back to it so have yourself a
great day
a great week and we will talk to you
next time
you
Transcript Segments
0.63

[Music]

26.16

well hello and welcome back

28

we are going to clean up a little bit

30.24

we're continuing to look at

32.48

some sort of the background data that we

34.719

want to track

36

uh lately we've been working our way

37.68

into passing values in so as we

40.8

uh go in here we added a road map

44.16

and then we for example want to create a

46.239

new time frame then we are

47.68

pre-populating

49.36

our our road map but we're doing it here

52.719

by sending variables in and we're going

55.199

to do i'm going to take a look at

56.32

another approach to doing this which is

58.719

um probably cleaner to some extent but

62.079

it does have some

63.68

some issues that you can run into based

66.159

on

66.96

browser but at least wanted to touch on

68.72

it and that's the idea of putting stuff

70.4

into the session

72.96

and the way we're going to do this is

74.32

we're going to uh whoops let me jump

76.88

over here

78.4

when we select a roadmap

82.32

then we're going to set a session value

84.96

of our current

86

id and what we're going to do there

89.92

is and it's not too complicated to do so

92.32

we've got

93.119

let's look at roadmap so we list

97.04

we can either create one or we can edit

99.759

one

101.439

now creating one is we're going to need

104.64

the id

105.52

of what we built and when we create one

108.24

we actually

108.88

ended up let's go look at this real

110.399

quick because i don't think we need it

112.64

so if we come here and create a new road

114.479

map i'm going to do let's do annual

116.56

goals

120.52

2022 get ahead of ourselves a little bit

124.479

and save a record and so here it's going

128

to bring us back here so

129.44

we don't really have to worry about it

130.72

on the create we're just going to do it

131.84

on the edit

133.36

which is awesome because we know exactly

135.52

what the idea is we don't have to do

137.84

something where we um insert a record

140.48

and then get the returned id

142.16

we actually have this so we go into edit

145.44

roadmap

149.12

because they're going to click here and

150.239

they give us an id so all we're going to

151.599

do is right away say if they're

153.92

authenticated then we can actually do

156.8

something here

157.68

and we're going to just say request

161.36

whoops if i can spell it right

164.4

dot session and we're going to call

167.68

this uh we'll just call it rmid

171.519

equals id so now we have set

176.4

a session variable and what we can do

180.64

is uh here when we do edit

184.72

and then for example create before we

187.68

were tacking in

189.68

attacking on the rd the id we don't need

192.08

to do that anymore so when we go

193.76

to roadmap edit

197.519

and we go here we're creating this

201.04

uh rm equals arm id and i'm going to

204.08

actually get rid of that

206.64

so now we're just going to create a time

208

frame

210.159

and when we do create time frame which

213.36

is tf which let's make sure i got that

216.48

right that goes to create time frame

222.72

great time frame there we go so we want

226.4

to do here

227.2

is we're looking for it in the request

230.959

now we're going to look for it in the

233.12

session

235.519

and we're really only going to change

236.72

this a little bit is we're just going to

237.92

say request.session

241.12

and we called it uh rmid

247.12

and we do it like that so now we're

248.72

going to check that within the session

250

now there's some things we could do

252.84

um we could create like a

256.079

essentially a function that checks a

258.32

session and pulls some values in

261.12

um but we're just going to keep this as

263.6

part of

264.88

so we could we could take these little

266.32

things and bundle this text up

268.639

and do it as part of something we return

270.479

back um

272.24

you know do these checkings and settings

273.84

but we're not going to bother with that

275.04

right now we're just going to keep it

276.08

very simple inline code

278.56

there will be some duplication so we'll

280.32

look at like create time frame

282.24

and there will probably be let's see if

284.24

we do like an edit time frame

288.72

edit time frame

292.72

oh well i guess in that case we don't

293.919

have to worry about it in the edit time

295.919

frame

296.479

um well we did do it here

303.28

so let's change that up

310

so here we said if it was in the session

312.24

uh that's going to be

318.96

well what did we have before let's take

320.4

a look at that real quick before

326

oh which is actually a problem there

327.28

because we have we were checking in the

328.72

get

329.52

but it actually should have been in the

330.72

post

334.16

so called a bug there um that should be

336.72

in the post

341.039

oh because we pass a road map in so here

344.08

we can do

347.28

actually this is in both of these so

348.639

we're going to do a request dot session

353.28

and we're gonna do we gotta clean this

354.72

up a little bit so if rmid

359.44

and request.session

363.84

actually is that the same thing then we

365.52

can take that

372

oh so let's go back to that was at the

375.039

bottom

375.68

so if we go here i think that was at the

378.24

bottom

379.28

yeah here we go

383.44

so let's just go ahead and sort of steal

385.44

that code and clean that up so else this

387.6

was if

388.56

let's see if

392.16

he's there but here he's going to do the

396.96

well we can just do this we want to call

398.639

him roadmap

406

uh rmid equals that okay and then here

410.08

we can do the same if he's in the co and

411.599

actually now we don't have to check

412.639

whether it's in the post

414

or the um the get

417.36

now we can just simply come through here

420.08

and say regardless we're going to say if

421.36

it's in the session

422.72

then we're going to go ahead and pull

424.319

that thing out

427.36

so that gives us for uh editing

431.199

so now

434.24

and we can probably find so that was

436.56

within

440.56

well we're probably in pretty good shape

441.759

so if we go to here if we go to

444.72

i think we're probably good let's see

446.24

i'll go test it out so now let's go

449.28

and if we edit

452.479

let's go edit here and this is our

455.44

overall

456.08

annual goals let's edit this and let's

458.88

say

459.28

overall let's see personal

464.879

we do personal goals

470.16

and it's an annual so we're going to

471.44

save that record

474.4

and oh that's interesting we ended up

476

posting here so now it's

480.08

so annual goals here if we look here

485.68

oh we didn't say oh oh i'm sorry because

488.24

this is a road map and then we go to

489.36

personal goals and we go here

491.68

and let's see does this return to 2021

495.599

it does

497.759

oh let's take a look at that link real

499.36

quick

500.8

make sure that we've got yep we're not

503.44

setting it up there

504.879

if we do create time frame are we

507.12

sending it here

508.16

we are so if we look at uh this is

511.599

time frame with child oh because that's

513.44

the oh that is the road map so

516.8

let's fix that one i thought we had that

518.159

somewhere else so let's go here

520.719

and we do edit time frame uh we had that

525.2

i think we also need a we had another

529.519

create time frame

535.68

let's edit did we call it yeah here it

539.44

is

539.92

down here at the bottom create time

541.44

frame

543.2

we oh we've got that one fixed

549.04

so okay so we're probably all right

552.08

we can go to the time frame i believe

553.839

it's time frame edit and we don't

555.6

have to send the roadmap

560.839

anymore and we also had it here

563.839

so we don't have to do it as

567.12

a part of the edit so let's make sure we

568.959

got both of those i think we did

571.44

so there's create time frame and edit

573.92

time frame

576.64

and that's where we clean that up so we

578.08

should be good there

582.48

so we've got personal goals and let's go

584.399

back up here and let's create

588.839

um

590.32

oh this is gonna be uh annual

594.32

personal goals and he doesn't have a

597.44

time frame parent uh we're gonna save

600.64

the record

602

and then um oh we got to clean this one

605.92

up

606.399

so when we do a oh this is all time

610.16

frames

611.279

so let's take it we'll take a look at

612.64

that in a second well not in a second

614.64

but

615.6

we'll take a look at a little bit later

617.279

so now let's go back to our roadmap

619.2

uh we have our personal goals we're

620.48

going to create a tank time frame

623.2

which is going to be uh

626.72

professional goals

630.88

and we'll call it annual professional

633.12

goals well we'll just keep

634.399

that because it is an annual time frame

636.48

we've got a road map

637.68

we're gonna save a record and

641.04

uh we can create a time frame here so

644.24

let's do that oh

645.04

so here we go id expected so here where

648.72

we do this p

652.16

we're not getting something back so

653.6

let's take a look at that

656.8

let's back it up so when we do create

660.64

time frame of this one

665.92

let's take a look at this guy so this

667.44

guy

669.04

is over here he doesn't have anything if

670.959

we go to edit professional goals

673.279

and do create a child time frame

678.079

uh let's see so one i'm still saying

680.399

this rm equals one so we've got to fix

682.24

that

682.8

so that was in

686.839

edit i guess

689.92

yes so editing a road map is still got a

692.959

bad a link that we don't need

698.399

let's see here

701.44

so we don't need that anymore

706.72

and then we went to edit professional

709.12

goals

710.959

create time frame i think this one that

712.8

broke oh no it didn't

720.079

so why was the p oh i think when we

722.56

created we were not

725.519

properly filling this out so that's what

727.519

we need to do and so that's a little bug

728.959

that we'll fix

730.079

we'll come into that next time actually

731.44

because what we'll do is when we create

733.76

a new

734.639

time frame we can't immediately do this

737.36

create time frame

739.12

so we need to have something where it

740.48

doesn't display this until

743.04

we have a a time frame id if we're

745.92

creating a new one

747.36

then we don't have the values because

750.88

here this create time frame

752.72

is actually filling this out and

754.16

actually what we're going to do is we're

754.959

going to correct that

755.76

as well so everywhere we have this

759.2

p we're going to also have

763.519

so we have uh create a time frame record

767.04

here so this is going to be

771.44

uh where we have this we're actually

773.36

going to be let's call this we're just

775.519

going to do it

776.24

tfid

779.36

i assume that is the oh that's the

784.839

parent

786

so let's do that we'll keep it there um

788.639

we'll call it p

789.36

we'll keep it that way so parent is

792.16

question

792.72

session uh if he is in that

796.32

request.session then we're gonna do

798.839

request.session

801.279

p and then dated.parents so we need to

805.36

find where we were using

807.2

parent

810.56

oops let's do it that way and let's see

815.36

so here it was in the post of a time

818.079

frame

823.199

and so let's see if request.pose time

825.76

frame which was going to be the parent

832.24

so this is an editing okay so

838.079

well we want to tweak this a little bit

839.76

so when we come into a task

843.519

editing a task

847.279

then a parent is here but what we need

850.48

to do

852.399

is say as we get through

860.8

so if we get a if we get one then we

864

need to do

864.88

the uh question.session

868.88

whoops

872.88

i need to set its parent

876.959

is going to be equal to oh i'm sorry it

879.68

was a p

883.12

is going to be data

886.32

dot

893.44

uh where did i set that where did i set

895.6

that data dot

896.959

parent i think it's just data apparent

898.399

so let's do that

900.8

oh but it's not oh it's not it's called

903.199

it's going to be actually data. time

904.639

frame we'll take a look at that guy real

905.92

quick

909.519

and so here we're going to have to

911.6

finish this one up next time so that's a

913.36

time frame period but a task

914.959

has a yes is a time frame

919.199

so we get down to here we need to set

923.199

here it's going to be his

926.48

so that'll be the parent that's like

927.92

basically the time frame where we're

929.36

currently in

934.639

and we're going to this is going to get

937.04

a little more complicated because we

938.56

could have

939.36

uh essentially a task a a

943.12

series of these going in so i think what

946.24

i want to do is wait and tackle that

947.68

next time around so hold that thought

950

and we will uh we'll come back in our

952.639

next episode and we're going to continue

954.24

working on this and this is going to be

956.399

two things we're going to look at our

957.44

time frames being able to access a

959.68

current parent

960.959

and then with the tasks making sure that

962.72

we're updating that parent as we go

964.24

which again

965.68

is where the session management of stuff

968.8

can get a little bit

970.399

complicated but that being said i'll let

973.199

you get back to it so have yourself a

974.639

great day

975.44

a great week and we will talk to you

978.16

next time

994.639

you