📺 Develpreneur YouTube Episode

Video + transcript

Learn Python And Django Day 44

2021-03-30 •Youtube

Detailed Notes

Part I of adding reports and working on dynamic data generation.

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

Transcript Text
[Music]
well hello
and welcome back we're continuing
looking at django and python
and this time we're going to do a little
bit of uh
dynamic adjustment to our some of our
buttons and display
we're actually working our way up to
reports and one of the first things i
want to do
is handle this little challenge here is
that we've got
tasks that are complete and we still
have a complete button there which
makes them you know very redundant so
what we want to do in that case
is we want to basically remove that
complete button we're only going to have
it
if they are not complete now we want to
go back into that so this is our
task list so what we're going to do is
we're going to go into
our task list page and it's actually
going to be a pretty simple change so
we're going to come in here
and instead of complete
we're just going to wrap that button
and what we're going to do is we're
actually going to do a
we're either going to just because of
the way it's set up
we're going to say that if it's not
uh if there's no button we're just gonna
do a space
uh just to make sure that it knows that
yes we do have something there
and then all we need to do is we're
gonna come in here and it's a very
simple kind of
uh equation we're just gonna say if task
dot
and the thing that matters is status
and if it is not equal to
i believe we called it complete with a
capital c yep if it's not equal to
complete
then we're going to have the complete
button otherwise we're going to space
so if we save that and rerun this
now what we saw here is that the uh the
status
is not coming out the way we want it to
and the problem here is because this
status
is actually going to be a
a status object a status instance so
instead what we have to do is we have to
take a look at our
status and we want to do name
uh we could do short name but we'll do
name for now
uh let's see wait where do we go oh
let's flip over here
to task list back over here
and we want status.name it's something
can be tricky in the django world
because you have things that look pretty
straightforward because here we're not
actually doing the name we could
but here it's because it is an instance
it's going to behind the scenes use the
tostring
which we're going to see if we look at
our models
it's probably just yep it's just the
name
so it's actually using that as so we can
directly
um we can direct we can directly call a
value as we do here
or we can basically say hey i want you
to display it and it's going to do the
string so that
that can sort of confuse things a little
bit but now if we run it
then we're gonna see that now everything
disappeared now note that this
is based on the name so we could uh
change this to i think we called it
short name
without an underscore
and i think we called that comp
i think of comp for the complete ones
and so now we can also do it yep same
thing
i said we can do it based on the short
values which we have talked about
when we were comparing for views i
remember i think we did that
somewhere around here we did a find
oh sorry how to find a filter
and
oh i can't find where we did it by short
oh yeah we did it up here we did it
like here we did short names to for the
get
uh to make sure that we're using sort of
our our own id and so we're going to use
that here
in this filter as well so now do some
basic you know cleaning up here of this
list
now the next step i want to get into is
actually starting to work on
although this is effectively a report i
want to actually get into
building a report of some sort for it
all we're going to do is we're just
going to steal our about so we're gonna
go back because we don't really need
that
so we're gonna go back to that was
internal
and about is now gonna be i'm gonna call
this reports
and we're gonna change over so we're
going to have a reports url
which means we need a reports url and we
can get rid of our about
completely so we're going to get rid of
that about page
i'm going to do a reports page
so now if we go into our view
pound page is going to be reports page
and we're gonna do all that instead of
about pages we can now
get rid of
we are going to
do this reports page
and we're going to move that we're going
to roughly base it off of task list so
let's just duplicate
that
and rename that to reports page
and our reports page is going oh if i
can open it there we go
let's see so we're probably not gonna
worry about
completing a task
we've got a title so let's go back over
to our view here
and we want a reports page
so we wanted to do there's going to be a
title
it's gonna be title and we're gonna call
that
uh let's see where did we do i don't
think we did them as
yeah so here we just did them as a
straight string so we're gonna come back
up here
reports page said our title this is
going to be
uh we're just going to call it reports
now we'll call reports home we'll do
that for now
let's go back to our report uh let's
and let's kill off a couple of these
windows
okay so we go back to our ports page and
now
let's keep it very simple
if we look here so we've changed over
reports of good reports
supports home and it's not doing
anything right now because we didn't
send it any
data that's useful so what we want to do
is the first thing we're going to do is
we're going to have a
task or i'm sorry report selector
and we're going to do this as a
let's see how we want to do this so
that's like uh
so reports home is a one let's just do a
little
uh we'll do it like an h yeah no we're
just gonna do bold
we'll actually make it strong not string
but strong
and this is going to be
report and we're going to make a list
and we're gonna have some options here
and this is gonna be a select
now what we're gonna do for now is we're
gonna keep it simple we're gonna
actually hard code our
various report options
and we'll just have them like numbered
but then we can come back later and we
can make it database driven if we would
like
and we may take care of that in this app
let's see if we want to do it so let's
see the first one we're going to do
will be tasks by
timeline
and then we want to do tasks by roadmap
and then we want to do let's just do
completed
tasks or let's do tasks by status
and so each of these is going to tweak
stuff a little bit
now we can do this a couple different
ways uh we can either
and we're going to talk about this you
know start implementing this on the
other side in a
next session uh but right now oops
reports yeah okay that one's good um
right now we've got reports and it's not
sending
any kind of parameters now what we can
do
is we could turn around and give it a
type
we can give it some parameters because
each report is probably going to have a
parameter
so we're going to have to think through
that a little bit how we want to do it
we can either have a
home page like we have here where we
select
and this is there's two different ways
you can do it but basically here you
come in you select report
and then maybe have it pull data and
provide some parameters and then pull
data like do an update
or you have a home and then each report
has its own page with
parameters now what we want to do is we
want to make it a little simpler
so what we're going to have is we're
going to have
uh here let's see we want to make this a
div
so we can actually do this in a couple
sections
so at the top well
we're gonna have our
and let's put like a break there just
because
and this needs to be we need to give
this an id so this is going to be
the id is going to be uh report type
because we're going to do some
javascript in this thing
to make it uh useful and then let's make
this
a um and then we're going to come in and
have another set well we're going to
have another row
and this one's going to be id equals
let's just call him reports
selector we're going to have another row
which is going to be
parameters
and then we're going to have down here
we're going to have results
and let's see that's going to end let's
see results it's going to be our if
tasks
blah blah blah blah blah then we're
going to come back here and then we'll
end that out
so we've got three sections and what we
want to do is here
we're going to start out with parameters
going to be blank
so we can do uh class i'm sorry let's
just be style
uh display none
and then we're going to uh let's just
call this
we're just going to put one here right
now which will be
uh we're just going to do this as some
parameters
for now so that we can see it so we come
in here
we're going to look then we get our
ability to
select reports but there's no parameters
right now because that's hidden
now what we want to do is we're going to
actually display parameters based on
what our selection is so we are going to
have a script
and we're gonna call this uh let's see i
don't know if i've got something that's
based on a selector real quick
i think i did so let me try if i look at
like time frame
and if we
because i want to see if i can steal one
well maybe not
yeah because i'm just making that call
well i'm actually going to use this a
little bit so let's just start from that
let's go back to that even though i
didn't think i was going to use it i'm
going to use it
so i'm not going to call it complete
test though i'm going to
steal this and right now oh this one's
going to be a little
see well let's do this
let me replicate that because i'm
actually going to steal that code not in
this episode but in the next
session we're going to talk about this
so first i'm going to do is i want to do
select report and it's going to be by an
id
and then here
let's do on change
equals
oh and actually i don't need
well i can probably do this let's see if
i just do id as
no i don't want to do that i'm going to
do it this way i'm not going to pass an
id
i'm just going to grab the
here
so i want to grab the id
and that's going to be equal to my
reports
selector
and so now that i've got my oops that's
my
selector and then id
we'll do a var here id equals uh
selector dot
value i think we can get that actually
we want uh i think it's called selected
value i gotta double check that one okay
this actually
i mean it's a value
and let's just do this so i'm gonna do
actually i've done this before some
extent so the element is going to be
uh parameters
and i'm just going to display them for
right now because i'm going to make some
display equals
here equals block so i'm going to go
display it
and let's see
let's do uh element
dot inner html
equals uh id
so we're just gonna sort of mess with
this a little bit right now because
we're going to be
running short on time on this one so
we're going to spill into this in the
next episode so first
let's do this now if i do a change
it's not triggering anything so we're
going to take a look at that
select report so it's not defined well
let's say select repo
oh because i have a typo
and now if i run it there we go oh it's
showing the id
it's not showing the value
so i don't want that in parameter in
parentheses i'm not i'm sorry in quotes
so do that and now
oh it's not getting the value so it's
not getting the id right so i'm going to
come back to this
uh selector.value so i'm gonna have to
correct this one for some reason it's
not
picking that up let's see so here
actually is my problem
is i need uh say selector
dot selected selected index
dot value let's see if that works out oh
sorry it's dot options
and then if i take that and do this then
now
we'll have oh it's still not doing it
doesn't like that uh
ah here's my problem it's not these
report sector text report type
is what i want to work off of
so it helps get the right type write
names so now
if i do this so now i've got my report
ids coming in and so
that's what wraps up this time i took a
little longer than i had expected
uh so we're going to do is next episode
we're going to start actually we're
going to generate one of these reports
and talk a little bit about how
to do that so that being said let's get
to it so
have yourself a great day a great week
and we will talk to you
next time
you
Transcript Segments
0.62

[Music]

26.32

well hello

27.279

and welcome back we're continuing

29.199

looking at django and python

30.96

and this time we're going to do a little

33.44

bit of uh

34.8

dynamic adjustment to our some of our

37.76

buttons and display

39.2

we're actually working our way up to

40.8

reports and one of the first things i

42.8

want to do

44.079

is handle this little challenge here is

46.32

that we've got

47.12

tasks that are complete and we still

50.32

have a complete button there which

52.32

makes them you know very redundant so

55.28

what we want to do in that case

56.719

is we want to basically remove that

58.96

complete button we're only going to have

60.48

it

61.199

if they are not complete now we want to

64.32

go back into that so this is our

66.64

task list so what we're going to do is

69.439

we're going to go into

71.04

our task list page and it's actually

73.84

going to be a pretty simple change so

75.36

we're going to come in here

77.68

and instead of complete

82.4

we're just going to wrap that button

87.6

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

88.799

actually going to do a

91.04

we're either going to just because of

94

the way it's set up

97.119

we're going to say that if it's not

100.24

uh if there's no button we're just gonna

101.68

do a space

103.6

uh just to make sure that it knows that

105.28

yes we do have something there

107.439

and then all we need to do is we're

108.56

gonna come in here and it's a very

109.68

simple kind of

110.64

uh equation we're just gonna say if task

113.2

dot

114.399

and the thing that matters is status

118.24

and if it is not equal to

123.52

i believe we called it complete with a

125.36

capital c yep if it's not equal to

126.96

complete

131.12

then we're going to have the complete

132.08

button otherwise we're going to space

134.4

so if we save that and rerun this

138.48

now what we saw here is that the uh the

141.52

status

142

is not coming out the way we want it to

144.08

and the problem here is because this

145.36

status

146.08

is actually going to be a

149.44

a status object a status instance so

151.92

instead what we have to do is we have to

153.36

take a look at our

154.879

status and we want to do name

158

uh we could do short name but we'll do

159.84

name for now

163.04

uh let's see wait where do we go oh

165.36

let's flip over here

167.599

to task list back over here

170.64

and we want status.name it's something

173.76

can be tricky in the django world

175.599

because you have things that look pretty

177.12

straightforward because here we're not

178.48

actually doing the name we could

181.12

but here it's because it is an instance

184.56

it's going to behind the scenes use the

186.56

tostring

188.319

which we're going to see if we look at

190.64

our models

191.92

it's probably just yep it's just the

193.599

name

195.12

so it's actually using that as so we can

197.28

directly

199.44

um we can direct we can directly call a

202.56

value as we do here

204.239

or we can basically say hey i want you

207.12

to display it and it's going to do the

208.4

string so that

209.28

that can sort of confuse things a little

210.879

bit but now if we run it

213.68

then we're gonna see that now everything

215.2

disappeared now note that this

217.2

is based on the name so we could uh

220.56

change this to i think we called it

222.159

short name

224.319

without an underscore

227.92

and i think we called that comp

231.44

i think of comp for the complete ones

234.48

and so now we can also do it yep same

237.36

thing

237.68

i said we can do it based on the short

239.12

values which we have talked about

241.12

when we were comparing for views i

243.2

remember i think we did that

246.08

somewhere around here we did a find

252.08

oh sorry how to find a filter

256.16

and

260.4

oh i can't find where we did it by short

262.32

oh yeah we did it up here we did it

264.88

like here we did short names to for the

268.24

get

269.199

uh to make sure that we're using sort of

270.639

our our own id and so we're going to use

272.96

that here

274

in this filter as well so now do some

277.36

basic you know cleaning up here of this

279.36

list

280.08

now the next step i want to get into is

282.8

actually starting to work on

284.96

although this is effectively a report i

287.44

want to actually get into

288.639

building a report of some sort for it

292.56

all we're going to do is we're just

293.44

going to steal our about so we're gonna

295.68

go back because we don't really need

296.88

that

297.36

so we're gonna go back to that was

299.44

internal

300.8

and about is now gonna be i'm gonna call

304

this reports

307.6

and we're gonna change over so we're

309.28

going to have a reports url

311.12

which means we need a reports url and we

313.36

can get rid of our about

314.72

completely so we're going to get rid of

317.68

that about page

321.6

i'm going to do a reports page

324.8

so now if we go into our view

330

pound page is going to be reports page

336.56

and we're gonna do all that instead of

338.96

about pages we can now

340.56

get rid of

346

we are going to

349.039

do this reports page

352.72

and we're going to move that we're going

353.84

to roughly base it off of task list so

356.72

let's just duplicate

357.919

that

361.52

and rename that to reports page

366.8

and our reports page is going oh if i

369.759

can open it there we go

372

let's see so we're probably not gonna

375.28

worry about

376.08

completing a task

380

we've got a title so let's go back over

382.16

to our view here

385.68

and we want a reports page

389.28

so we wanted to do there's going to be a

391.28

title

393.68

it's gonna be title and we're gonna call

395.6

that

397.12

uh let's see where did we do i don't

398.639

think we did them as

401.28

yeah so here we just did them as a

403.36

straight string so we're gonna come back

405.039

up here

406.88

reports page said our title this is

409.12

going to be

412.639

uh we're just going to call it reports

417.599

now we'll call reports home we'll do

420.24

that for now

423.28

let's go back to our report uh let's

427.199

and let's kill off a couple of these

429.039

windows

432

okay so we go back to our ports page and

434.4

now

435.52

let's keep it very simple

439.039

if we look here so we've changed over

441.36

reports of good reports

442.639

supports home and it's not doing

444.16

anything right now because we didn't

445.84

send it any

447.12

data that's useful so what we want to do

450.96

is the first thing we're going to do is

452.08

we're going to have a

454

task or i'm sorry report selector

458

and we're going to do this as a

461.919

let's see how we want to do this so

464.639

that's like uh

465.599

so reports home is a one let's just do a

467.599

little

468.72

uh we'll do it like an h yeah no we're

471.12

just gonna do bold

472.879

we'll actually make it strong not string

476.08

but strong

477.199

and this is going to be

484.319

report and we're going to make a list

490.8

and we're gonna have some options here

494.319

and this is gonna be a select

497.52

now what we're gonna do for now is we're

500.639

gonna keep it simple we're gonna

501.68

actually hard code our

502.96

various report options

506.4

and we'll just have them like numbered

511.84

but then we can come back later and we

513.599

can make it database driven if we would

515.68

like

516.479

and we may take care of that in this app

518.24

let's see if we want to do it so let's

519.36

see the first one we're going to do

521.2

will be tasks by

524.399

timeline

527.44

and then we want to do tasks by roadmap

534

and then we want to do let's just do

536.64

completed

537.76

tasks or let's do tasks by status

546.399

and so each of these is going to tweak

548.64

stuff a little bit

549.68

now we can do this a couple different

551.519

ways uh we can either

553.36

and we're going to talk about this you

555.2

know start implementing this on the

556.32

other side in a

557.519

next session uh but right now oops

560.56

reports yeah okay that one's good um

564

right now we've got reports and it's not

566.56

sending

567.04

any kind of parameters now what we can

569.519

do

570.16

is we could turn around and give it a

571.6

type

573.279

we can give it some parameters because

575.44

each report is probably going to have a

577.04

parameter

578.56

so we're going to have to think through

580.48

that a little bit how we want to do it

581.76

we can either have a

583.12

home page like we have here where we

585.92

select

586.88

and this is there's two different ways

588.88

you can do it but basically here you

590.16

come in you select report

592.32

and then maybe have it pull data and

594.399

provide some parameters and then pull

595.839

data like do an update

597.6

or you have a home and then each report

600.8

has its own page with

602.48

parameters now what we want to do is we

604.56

want to make it a little simpler

607.279

so what we're going to have is we're

609.76

going to have

610.72

uh here let's see we want to make this a

614.16

div

616.24

so we can actually do this in a couple

618

sections

619.36

so at the top well

624.88

we're gonna have our

629.519

and let's put like a break there just

631.6

because

634.72

and this needs to be we need to give

636.56

this an id so this is going to be

638.64

the id is going to be uh report type

641.12

because we're going to do some

641.92

javascript in this thing

644.399

to make it uh useful and then let's make

648.24

this

648.88

a um and then we're going to come in and

651.2

have another set well we're going to

652.32

have another row

656.88

and this one's going to be id equals

664.56

let's just call him reports

669.04

selector we're going to have another row

675.04

which is going to be

686.839

parameters

688.64

and then we're going to have down here

692.16

we're going to have results

698.32

and let's see that's going to end let's

701.279

see results it's going to be our if

702.64

tasks

703.36

blah blah blah blah blah then we're

704.64

going to come back here and then we'll

705.76

end that out

710.079

so we've got three sections and what we

712.16

want to do is here

713.519

we're going to start out with parameters

714.88

going to be blank

718.24

so we can do uh class i'm sorry let's

721.44

just be style

726.72

uh display none

733.2

and then we're going to uh let's just

735.76

call this

737.279

we're just going to put one here right

738.48

now which will be

741.04

uh we're just going to do this as some

742.839

parameters

746.56

for now so that we can see it so we come

749.12

in here

751.2

we're going to look then we get our

753.76

ability to

754.639

select reports but there's no parameters

756.8

right now because that's hidden

760.959

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

762.639

actually display parameters based on

766.32

what our selection is so we are going to

768.48

have a script

772.8

and we're gonna call this uh let's see i

775.519

don't know if i've got something that's

776.32

based on a selector real quick

778.16

i think i did so let me try if i look at

780.48

like time frame

782.16

and if we

786.8

because i want to see if i can steal one

788.8

well maybe not

796.56

yeah because i'm just making that call

797.92

well i'm actually going to use this a

799.44

little bit so let's just start from that

801.12

let's go back to that even though i

802.16

didn't think i was going to use it i'm

803.12

going to use it

804.48

so i'm not going to call it complete

806.24

test though i'm going to

808.079

steal this and right now oh this one's

810.079

going to be a little

811.279

see well let's do this

814.639

let me replicate that because i'm

815.92

actually going to steal that code not in

817.6

this episode but in the next

819.36

session we're going to talk about this

820.48

so first i'm going to do is i want to do

823.6

select report and it's going to be by an

826.88

id

828

and then here

831.839

let's do on change

840.839

equals

843.839

oh and actually i don't need

847.68

well i can probably do this let's see if

849.68

i just do id as

852.32

no i don't want to do that i'm going to

853.92

do it this way i'm not going to pass an

855.199

id

855.519

i'm just going to grab the

859.04

here

863.44

so i want to grab the id

866.88

and that's going to be equal to my

869.279

reports

870.32

selector

877.76

and so now that i've got my oops that's

879.76

my

883.04

selector and then id

886.32

we'll do a var here id equals uh

889.6

selector dot

893.92

value i think we can get that actually

895.92

we want uh i think it's called selected

899.519

value i gotta double check that one okay

902.72

this actually

903.44

i mean it's a value

907.12

and let's just do this so i'm gonna do

911.12

actually i've done this before some

912.399

extent so the element is going to be

916.16

uh parameters

919.199

and i'm just going to display them for

920.8

right now because i'm going to make some

923.76

display equals

929.759

here equals block so i'm going to go

931.6

display it

934.56

and let's see

940.639

let's do uh element

943.68

dot inner html

947.44

equals uh id

950.8

so we're just gonna sort of mess with

952.24

this a little bit right now because

953.36

we're going to be

954

running short on time on this one so

956.16

we're going to spill into this in the

957.36

next episode so first

960.399

let's do this now if i do a change

963.6

it's not triggering anything so we're

965.12

going to take a look at that

968.16

select report so it's not defined well

970.959

let's say select repo

972.079

oh because i have a typo

977.04

and now if i run it there we go oh it's

979.92

showing the id

980.56

it's not showing the value

984.399

so i don't want that in parameter in

986

parentheses i'm not i'm sorry in quotes

989.6

so do that and now

994

oh it's not getting the value so it's

995.519

not getting the id right so i'm going to

997.519

come back to this

1000.639

uh selector.value so i'm gonna have to

1003.36

correct this one for some reason it's

1005.199

not

1005.92

picking that up let's see so here

1009.199

actually is my problem

1011.839

is i need uh say selector

1016.48

dot selected selected index

1020.16

dot value let's see if that works out oh

1023.36

sorry it's dot options

1029.36

and then if i take that and do this then

1032.48

now

1032.959

we'll have oh it's still not doing it

1035.679

doesn't like that uh

1038.64

ah here's my problem it's not these

1040.959

report sector text report type

1043.039

is what i want to work off of

1046.64

so it helps get the right type write

1048.96

names so now

1052.48

if i do this so now i've got my report

1054.24

ids coming in and so

1055.76

that's what wraps up this time i took a

1057.52

little longer than i had expected

1059.52

uh so we're going to do is next episode

1062.4

we're going to start actually we're

1063.36

going to generate one of these reports

1064.72

and talk a little bit about how

1066

to do that so that being said let's get

1068.64

to it so

1069.52

have yourself a great day a great week

1071.919

and we will talk to you

1073.679

next time

1089.919

you