TRANSCRIPTEnglish

Django Project – Code a CRM App Tutorial

2h 23m 41s24,803 words3,558 segmentsEnglish

FULL TRANSCRIPT

0:00

in this course you will learn how to

0:01

build a powerful CRM application using

0:04

Django Python and MySQL you also learn

0:07

how to use Version Control with Git and

0:09

GitHub and how to configure MySQL for

0:12

your application John Elder teaches this

0:14

course he is an experienced instructor

0:17

who has created many popular courses

0:19

what's going on guys John Alder here

0:21

from codemy.com and in this video we're

0:22

going to create a basic CRM app with

0:24

Django and python

0:27

all right guys like I said in this video

0:29

we're going to build this basic CRM app

0:31

with Django and python but before we get

0:33

started if you like this video you want

0:34

to see more like be sure to smash like

0:35

button below subscribe to the channel

0:36

give me a thumbs up for the YouTube

0:37

algorithm and check out codemy.com where

0:39

I have dozens of courses with thousands

0:40

of videos to teach you to code use

0:42

coupon code YouTube 50 to get 50 off

0:44

lifetime membership it's all my courses

0:45

videos and books for one-time fee which

0:47

is insanely cheap all right as like I

0:48

said in this video we're gonna build

0:49

this basic CRM tool with Django and

0:52

python CRM customer relationship manager

0:55

management you know what I'm talking

0:56

about this will allow us to add customer

0:59

records see John Elder address city

1:01

state ZIP code date created anything

1:03

else you want phone number or whatever

1:05

and then add it to the database we can

1:07

click on one of these guys and we can

1:09

see the record we can update the record

1:11

if we want so John 2 update this record

1:14

boom John 2 Elder if we want to we can

1:18

update the record back

1:21

there we go uh we can come down here

1:23

maybe we don't want a record anymore we

1:25

can delete it

1:26

record is deleted successfully we've got

1:28

this nice table when you hover over it

1:30

it sort of changes color so you can sort

1:33

of play around with it and it's very

1:34

cool we can log in and log out so we

1:37

could also register so you can create

1:39

accounts log in

1:41

see I'm as admin here and then here we

1:44

go so that's we're going to be building

1:45

this video this should be a complete

1:46

video I'm going to start at the

1:47

beginning go all the way through it and

1:48

this should be a lot of fun so let's

1:50

head over to our terminal I'm using the

1:51

Sublime Text Editor and the gitbash

1:52

terminal as always and as always you can

1:54

find a link to the code in the pin

1:55

comment section below so check that out

1:57

if you're interested so I've just got a

1:59

basic get bash terminal opened up and uh

2:01

you can see I'm just in my default

2:02

directory so let's create a directory

2:04

we're going to hold all this stuff so

2:06

I'm going to say mkdir I want to put it

2:08

in my C drive and I'm just going to call

2:10

this uh Django CRM dcrm whatever so now

2:14

we need to move into that directory so

2:16

CD

2:18

dcrm and when we do when we type in LS

2:21

to list the stuff here there's nothing

2:23

in there so all right that looks good

2:25

now I should mention before we get

2:26

started I'm going to be using a mySQL

2:28

database for this one just because I get

2:30

a lot of requests from my Sequel and

2:31

Django and I don't really understand

2:34

when that happens because the point of

2:36

Django is that it abstracts away the

2:38

database layer so it doesn't matter what

2:40

database you use you can use any data

2:41

base it's irrelevant you're not going to

2:43

be doing like my SQL commands in this

2:44

you're just going to be doing regular

2:46

Django database coding but I keep

2:48

getting questions about the mySQL

2:50

database so that's we're going to use in

2:51

this video you could swap this out for

2:53

postgres most people will use postgres

2:55

because when you push this online

2:57

postgres is the most popular and easy to

2:59

use database with Django and everything

3:01

else but you can use MySQL too it just

3:03

takes a few extra steps to get it going

3:04

so we're going to be using my SQL this

3:06

one just to mix things up a little bit

3:07

and it should be fun but like I said if

3:09

you want to use postgres it's very

3:10

simple to swap out postgres instead it's

3:13

just basically a couple of settings that

3:15

you need to configure so no big deal so

3:17

all right let's head back over here and

3:19

let's first create a virtual environment

3:21

we always create a virtual environment

3:22

so I'm going to go python Dash m v e n v

3:25

and let's call our virtual environment

3:27

vert sure for virtual hit enter this

3:30

should spin right up all right so now

3:31

when we hit LS we can see there's a vert

3:33

directory so let's turn this on let's go

3:35

Source vert scripts activate so now we

3:40

see this vert here so that we know the

3:42

virtual environment has been turned on

3:43

so all right let's pip install Django

3:46

the first thing we need

3:49

all right we're good there now we also

3:51

want to pip install MySQL

3:54

now we're also going to have to actually

3:55

download MySQL onto your computer from

3:58

their website we'll look at that in just

3:59

a second but uh we'll need to do that

4:01

next we need a connector to connect our

4:04

Django app to our MySQL app so there's a

4:06

couple of them so you can pip install

4:09

my SQL Dash connector that's the

4:13

original one go ahead and try that and

4:15

you may be fine but more likely than not

4:16

you're gonna have to install pip install

4:18

MySQL connector Dash python so I know

4:22

I probably need that

4:24

but

4:25

if for good measures you can install the

4:27

regular one as well if one of them works

4:30

the other one won't be needed and vice

4:32

versa so okay we're good there okay so

4:34

now we need to download and install my

4:37

SQL so I'll put a link somewhere to this

4:39

let's head over to a web browser and

4:41

just head over to this website

4:43

dev.mysql.com forward slash downloads

4:45

forward slash installer and we want the

4:48

MySQL installer for the community

4:50

version right and it's 437 megabytes go

4:54

ahead and click here to download now I'm

4:55

not going to do this because I've

4:56

already downloaded it's a little bit

4:58

tedious process you have to click next a

5:00

bunch of times and it installs a bunch

5:01

of stuff takes like five or ten minutes

5:02

to install this thing the important

5:05

thing here is when you install it it

5:06

will ask you to set up a username and a

5:08

password and root is probably the

5:10

username you're going to want to set up

5:11

it may default to root but if it doesn't

5:14

type in root for the username and for

5:16

your password pick whatever you want but

5:17

remember that password because we're

5:19

going to need it to connect to the

5:21

database later on in our Django app so I

5:23

think mine is just password one two

5:25

three so whatever for the purpose of

5:28

this that's fine but you know pick a

5:29

good password now once you install it

5:31

you'll need to turn it on there's

5:33

probably an option that says at the very

5:35

end you know start my sequel click yes

5:37

it needs to be running sort of in the

5:39

background you won't notice that it runs

5:40

in the background of windows so just

5:42

make sure that's turned on so okay let's

5:44

now head back over to our terminal all

5:46

right so let's head back over to our

5:47

terminal I'm still in my cdcrm directory

5:49

our virtual environment is still there

5:50

it's still turned on let's go ahead and

5:53

create our project so let's go Django

5:55

Dash admin start project and I'm just

5:59

going to name this dcrm

6:01

so now we see this dcrm directory so now

6:04

I'm going to change directory into it so

6:06

so CD change directory into dcrm and we

6:10

can see here's our manage.pi file so

6:11

that's cool so now we need to create an

6:13

app inside of our project so let's go

6:15

python manage.pi start app and let's

6:18

name this website because basically this

6:20

is a website so I'm just going to call

6:22

it website so now when we LS we could

6:24

see there's that directory so okay we've

6:27

got our stuff now let's head over to

6:28

Sublime Text and add all this in come up

6:31

to project add folder to project

6:33

navigate to your C drive and then find

6:35

that dcrm directory double click it go

6:39

inside of it click the second one just

6:41

once to highlight it click select folder

6:43

and boom there we go so the first thing

6:45

we need to do is make some changes to

6:47

our settings.pi file so I'm going to get

6:50

rid of our comments here and let's come

6:52

down here to installed apps we need to

6:53

add our app so we call that website

6:57

there we go now we need to come down

6:59

here and configure our database section

7:01

because by default Django uses sqlite3

7:04

but we want to use like I said my SQL

7:05

for this one so we need to make some

7:07

changes the Django DB back ends should

7:09

be pointed to my SQL now and we can get

7:13

rid of this

7:14

but we need to add some things first we

7:16

need to add a name so I don't know what

7:19

you want to name your database let's

7:20

call it I don't know Elder Co something

7:22

like that Elder company whatever name it

7:25

whatever you want and then now we need

7:27

to set the user and this is the user

7:29

that you set up when you installed my

7:31

SQL so it should be root or whatever you

7:35

set up next we need to designate the

7:37

password

7:39

and again that's that same password you

7:41

set up when you installed my SQL mine

7:43

was password one two three pick

7:46

something better than that

7:48

I'm just doing this on my local computer

7:50

so it doesn't really matter next we need

7:52

to set the host

7:53

so

7:54

this is just on our local computer so

7:56

it's going to be a local host

7:58

and then finally we need to set the port

8:00

my sequel generally runs on Port

8:04

3306 and that looks good you can I think

8:08

maybe change that during installation of

8:09

my SQL but you don't want to just take

8:12

the default so okay go ahead and save

8:13

this and we're good to go there so now

8:16

we need to set up that database that we

8:18

just designated remember we called it

8:21

Elder Co right we need to create that so

8:23

what I'm going to do is come back to my

8:26

terminal and we're in our dcrm dcrm

8:29

directory it's the same one that has our

8:32

manage.pi file right and I'm just going

8:35

to create a file using the touch command

8:37

and let's call this mydb dot Pi there's

8:40

lots of different ways you could do this

8:41

but this is really kind of the easiest

8:42

in my mind so we'll just do that head

8:45

back to our Sublime Text and you can see

8:46

there is our file so really quickly let

8:50

me just comment in some things we've

8:52

done so far so we want to install MySQL

8:54

this is the URL to the installation

8:56

thing we want to pip install MySQL we

8:58

also need a connector so either the

9:00

basic one or more likely this one

9:02

whichever one works on your computer try

9:05

them both maybe try this one to begin

9:06

with if it doesn't work try this one in

9:09

my case I know I I need this one on my

9:12

computer so I just would do that one but

9:14

you could try them both there's no harm

9:15

in that so now we need to import MySQL

9:19

dot connector

9:22

okay

9:23

that's this guy or this guy they both go

9:25

by that and we need to create a database

9:28

connection so I'm going to create a

9:29

variable called database and this is

9:31

going to be a MySQL dot connector

9:35

dot connect

9:37

and then inside here we need to

9:39

designate some things so host is we know

9:41

localhost and then our user we know is

9:44

root

9:46

and our password is now notice this is

9:49

past WD pass would not password that's

9:53

just the convention we know that that is

9:55

going to be password one two three

9:57

because I'm very lazy all right and

10:00

there we go so now we want to prepare

10:03

a cursor object and this might seem like

10:07

a lot of work but it's really not too

10:08

bad just a few more lines of code so we

10:10

want a cursor object and we want to set

10:14

that to database dot cursor

10:17

and that database is this thing right

10:20

here that we just defined right

10:22

we also now need to create the database

10:25

right so we can do that by calling this

10:28

guy

10:29

paste that in dot execute

10:33

and this is just a MySQL command to

10:35

create a database

10:36

we just create database and what do we

10:39

want to call it we want to call it Elder

10:41

Co right

10:42

now we can give a little message here to

10:44

the terminal if we want all done

10:46

something like that and go ahead and

10:48

save this file so we're only going to

10:50

need this right now one time just to

10:52

sort of set up this database and if you

10:54

know how to set up a database by hand in

10:55

the terminal you could do it that way

10:57

too or you could go to the MySQL

10:59

workbench and do it there however you

11:01

want to create your database you can but

11:02

this is super easy so I'm just going to

11:04

do it like this so let's head back over

11:06

to our terminal here and if we LS we see

11:09

sure enough there's that file so let's

11:10

just run it so let's go python

11:14

mydb.pi and boom it says all done and we

11:17

should be good to go now if you want to

11:18

confirm this you can open up your MySQL

11:20

workbench and let's see here

11:23

we could come down here to schemas and

11:26

when we hit refresh we see now there's

11:29

an elder Co

11:30

database in there right so okay that

11:33

looks like it worked so all right we're

11:35

pretty much done with the MySQL stuff

11:36

that's the extent of all the MySQL stuff

11:38

we're going to have to do uh we're

11:40

pretty much good to go now we can make

11:41

sure this worked by coming up here

11:44

clearing the screen and running python

11:47

manage.pi migrate because by default

11:50

Django comes with a bunch of database

11:52

stuff that needs to be pushed into the

11:53

database with a migration right out of

11:55

the box so we could do that now and if

11:58

this works boom boom boom we should be

12:00

all good to go now we can again confirm

12:03

this if we want in our MySQL workbench

12:07

we can click on tables and you can see

12:09

now there's a bunch of Django stuff in a

12:11

table in our Elder code database right

12:14

so that looks like it worked and we're

12:16

good to go so

12:17

all right that looks good one last thing

12:19

I want to do in this sort of area is

12:21

create a user so to do that

12:24

I'm gonna go win PTY and then python

12:27

manage.pi create super user

12:32

now I'm using the win PTY command

12:34

because I'm on Windows and get bash and

12:36

you have to if you're on a Mac or

12:37

something else Linux you can leave off

12:39

this win PTY and the command is just

12:40

python manage.pi create super user so

12:43

let's do that and I want to set the

12:45

username to admin and we don't need an

12:47

email address and then set a quick

12:49

password

12:50

okay we're good to go so now

12:53

let's run our server and see if this all

12:55

works so python manage.pi runs server

13:00

that looks good head back over to the

13:02

browser and when I hit reload here at

13:04

localhost 8000 boom we get this Django

13:08

start screen which means everything

13:09

works out and we are good to go so we

13:11

have set up our project everything is

13:12

working we've got a mySQL database

13:14

installed and connected and we're ready

13:16

to start building this thing out

13:22

so before we start building this thing

13:25

out let's set up Version Control very

13:27

quickly with Git and GitHub just so you

13:30

guys can check my code as I'm going

13:31

along if you want to watch that so to do

13:33

that we head back over to the terminal

13:35

hit control and see at the same time to

13:37

break out of our server and now we just

13:40

need to set up git and I've already got

13:42

an SSH key created on my computer if you

13:45

don't know how to do that check the

13:46

channel there's tons of videos on

13:48

setting up an SSH key you need an SSH

13:50

key to connect to GitHub I've also got

13:53

lots of videos on connecting to GitHub

13:54

for the first time if you don't know how

13:55

to do that so I'm just going to run

13:57

through this as if you already know so

13:59

head over very quickly to this webpage

14:02

codemy.com forward slash git these are

14:05

the commands to set up git on a project

14:07

and I never remember them I just come to

14:09

this page and uh copy and paste them so

14:12

this is the first one we just need to

14:14

copy each of these and paste them into

14:15

the terminal real quick so head back

14:17

over here right click paste and enter

14:20

your name John Elder hit enter boom that

14:23

one's good the next one is email address

14:26

so copy that head back over here

14:30

right click paste and here's my email

14:32

address

14:34

johnny4196

14:35

gmail.com I suggest you use the same

14:38

email address that you use at GitHub

14:40

this makes things easier

14:42

next we have this guy's copy him

14:47

and like I said I don't remember what

14:49

these commands do I just know that every

14:51

time we want to set up git we need to

14:52

paste them in so that's what I do I've

14:54

been pasting these commands in for like

14:55

20 years they never change and I still

14:58

don't really know or care what they mean

15:00

that's just what we do so add back over

15:03

here

15:04

paste enter and the last one I do

15:07

remember the last one it is get a knit

15:10

so there we go here

15:13

boom boom get a knit okay so now we see

15:17

this master on here that's the master

15:19

branch that means git has been basically

15:22

uh installed and it's been turned on so

15:25

now we need to put all of our files in

15:26

there so let's go get add period git

15:30

commit Dash am let's call this the

15:32

initial commit

15:35

all right so we've committed it all now

15:37

we need to push it up to GitHub and in

15:39

order to do that we need to go over to

15:40

GitHub real quick so go to github.com

15:43

login

15:45

so my username is I think flat Planet no

15:48

I don't think the world is flat I just

15:49

find it hilarious some people do okay

15:52

and then click on repositories

15:56

and then let's create a new one and I'm

15:59

gonna call this Django CRM and this will

16:03

just be public so we'll click create

16:05

Repository

16:07

and then we need to come down here to

16:08

push existing repository from the

16:10

command line and we need to enter these

16:12

commands into our terminal one at a time

16:14

so let's paste this guy in

16:17

alrighty then this one will change the

16:19

name of our Master Branch from Master to

16:22

Main

16:23

common now

16:25

so you can see now it says main there

16:27

and then finally the last one is just to

16:29

push all of our code up to GitHub

16:32

we'll grab this guy paste it in

16:35

and boom that looks good so now when we

16:38

come back here and hit reload

16:40

you can see here's all the code that we

16:42

have so far and we can confirm that we

16:44

can click this dcrm go to settings you

16:47

can see up there it says website we made

16:48

that change and then we come down here

16:50

and see up here's all the database stuff

16:52

Elder co root now your password is right

16:55

here this is open so if you're doing

16:58

this professionally when you set up your

17:00

repository you want to probably set that

17:02

up as private right so remember I picked

17:06

public

17:08

um but we can let me show you here again

17:09

go to repositories

17:12

click new name it and then right here

17:14

where it says public instead you would

17:16

click private so people won't be able to

17:18

see your code right but for our purposes

17:20

I don't really care I don't care that

17:22

you guys know that my mySQL database is

17:24

password123 there's nothing in there you

17:25

can't hack it well I suppose you could

17:27

hack it but there would be no reason to

17:29

there's nothing interesting in there so

17:30

there you go so okay that looks good

17:34

so all right we're moving right along so

17:37

now let's come back here and let's run

17:39

our server so python manage.pi run

17:42

server

17:44

head back over to the website make sure

17:46

that's working hit reload okay we're

17:48

good to go there so all right let's

17:50

start building this thing out so let's

17:51

head over to our code now you could

17:53

delete this mydb.pi file we do not need

17:55

it at all anymore I'm going to leave it

17:57

in here just so you guys can reference

17:58

it if you want if you head back over to

18:01

github.com

18:03

planet and then click on the Django CRM

18:06

director you can see here it is right

18:08

there if you want to copy and paste it

18:10

or whatever you can do that so okay so

18:12

let's start to build this thing out

18:19

so let's head over to our code and start

18:21

building this thing out so I can close

18:23

out our dcrm folder we're going to be

18:26

working mostly from now on in our

18:27

website folder here so actually know

18:30

that we do need to do one thing first in

18:32

this folder that we didn't do we need to

18:33

play around with our urls.pi file so

18:36

open up this file

18:38

and here we need to add include

18:42

and we go there and we need to create a

18:45

new path so I'm going to call this two

18:47

single quotation marks nothing in

18:48

between them and we want to include

18:52

our website

18:54

dot URLs file

18:57

right now we don't have a URLs file in

18:59

our website directory yet we need to

19:01

create that so I'm just going to copy

19:03

all this and close this head over here

19:05

to our website directory right click new

19:07

file and then file save as and let's

19:10

call this urls.pi

19:13

and paste in that code now we don't need

19:15

this and we don't really need this

19:18

include and we really don't need that

19:21

okay so let me minimize this dcrm

19:25

directory again we're not going to be

19:26

using that much at all if at all from

19:28

now on and okay so instead of this

19:31

thing right here let's create a new home

19:34

page so anytime in Django when you want

19:36

to create a web page it's always a

19:37

three-step process you create the actual

19:39

template file the actual HTML page you

19:42

also create a URL and you create a view

19:44

so let's start out with creating a URL

19:46

right here and this is going to be our

19:48

home page so we could just so we just

19:50

want it to be in root which is nothing

19:52

just two single quotation marks and we

19:55

want to point this to views dot home

19:57

let's call it and let's give this a name

20:00

equal to home now up here we need to

20:03

import our views so let's go from period

20:07

import views

20:09

okay so this is our URL we're good there

20:12

now let's head over to our views.pi file

20:14

and let's create our home page view so

20:17

let's define home we want to pass in our

20:20

request as always

20:21

and then here for now we just want to

20:24

return

20:25

render

20:26

request and then we want to point this

20:30

to home.html now this doesn't exist yet

20:32

but we'll create it in a second and we

20:34

want to pass an empty context dictionary

20:36

so okay that's good there now we need to

20:38

create this home.html file so let's head

20:40

over to our website directory right here

20:42

right click and create a new folder and

20:45

then down here at the bottom let's name

20:46

it templates now Django knows to look

20:48

for all web page files in the templates

20:51

directory so it will just know to look

20:52

there so we can create a new file file

20:55

save as and we want to call this

20:57

home.html and for now I'm just going to

20:59

say uh hello world just to make sure

21:01

this is working

21:03

go ahead and save this now we can head

21:06

back over to the website and click

21:07

reload and hopefully that worked oh we

21:10

got an error because let's see no model

21:12

named website URLs ah let's go ahead and

21:15

break out of our server run it again now

21:18

that should work

21:21

just need a little reset there when we

21:23

made a change there to the settings.pi

21:24

file and boom there we go hello world so

21:27

we've got our first web page so very

21:28

cool now let's set up the base.html file

21:31

and a base.html file is just the file

21:33

that every web page on your site will

21:35

reference and it'll pull like the

21:37

headers and the Footers out of right so

21:39

I'm going to come over to templates

21:41

right click new file file save as we

21:43

want to call this base.html and inside

21:46

of here we want to put all of the code

21:48

that's going to go on every page so the

21:50

code we're going to use for our styling

21:52

is something called bootstrap the

21:53

bootstrap CSS framework it's the most

21:55

popular CSS framework and we can use

21:57

that for free by going to

21:58

getbootstrap.com clicking on the docs

22:01

and then just coming down here and we

22:03

want the one with CSS and JavaScript so

22:05

I'm just going to copy this to clipboard

22:07

and then we just want to come back here

22:08

and right click and paste all of this

22:11

stuff into our base.html file and up

22:13

here the title let's change this to

22:15

Django CRM something like that and then

22:19

here where it says hello world we need

22:21

to take this out and add a little tag

22:24

and the tag we want to use is a Django

22:26

tag and it's the block content tag

22:31

right so that's the opening block

22:33

content tag we also need a closing one

22:35

so type in in Block here all one word

22:37

and basically what this does is it will

22:39

pull everything out of our web page in

22:42

this case all we have in there is this

22:45

stuff it will Django will basically pull

22:47

stuff out of there and it will place it

22:49

inside of this tag right but it'll do it

22:52

behind the scenes so okay that's cool

22:55

now we need to come back over here and

22:56

make a quick little change we need to

22:58

say hey use that file right so up here

23:00

at the top we want to extends

23:04

base.html

23:06

right and then in this page we need to

23:08

wrap everything that we want that

23:10

based.html file to use inside that same

23:14

block content tag so here we can just

23:16

type that in real quick so that's block

23:18

content

23:20

and then again we need to close that tag

23:22

down here so end block okay go ahead and

23:26

save this make sure that base.html file

23:29

has been saved so now let's head back

23:30

over to our website and see if that

23:32

works now notice the text it's all kind

23:34

of Blocky and dark if we click reload oh

23:37

we get an error ah I didn't put a

23:40

quotation mark at the end of that

23:42

uh head back over to our home yeah there

23:44

we go right there typos

23:48

I'm the master of typos it's gonna

23:50

happen a lot all right so boom now you

23:52

see the text is skinnier it's kind of

23:54

not as blocky that means bootstrap has

23:56

been installed and we're good to go so

23:58

all right that looks good now this is

23:59

shoved right up here in the top we need

24:01

to change that a little bit and we can

24:03

do that by going over to our base.html

24:05

file and wrapping this whole thing in a

24:07

bootstrap div called

24:10

container

24:12

right like that and we need to close our

24:14

div there we go and if you want you can

24:17

tab this over to make it look pretty so

24:19

now if we save this and head back and

24:20

hit reload boom it pops it over a little

24:23

bit you might also want to add a little

24:25

line break or something so I'll just add

24:28

a br line break tag come back over here

24:31

hit reload boom and we're good to go so

24:33

all right that looks good now let's

24:35

create a nav bar so let's head back over

24:37

to our templates directory right click

24:39

and create a new file I'll save as let's

24:42

call this

24:43

navbar.html and we're going to grab that

24:45

from bootstrap as well because it's

24:47

super easy head it back over to

24:48

bootstrap scroll down to components and

24:52

then look for navbar now there's navbar

24:54

and navs and tabs you don't want navs

24:57

and tabs you just want nav bar so I'll

24:59

go ahead and click that and then just

25:01

come down here and find one that you

25:02

like I like this one right here so we'll

25:04

go ahead and copy this

25:06

and we can head back over to our

25:07

navbar.html right click and paste all

25:09

this in so let's just go ahead and save

25:11

this and see what we got right out of

25:12

the back now we need to add this to our

25:15

base.html file so we'll come back over

25:17

here and right under the body tag let's

25:20

add another Django tag called include

25:23

and here we could just include our

25:26

navbar.html close your quotation mark

25:29

there and that should be it so let's go

25:31

ahead and save this head back over here

25:33

and let's hit reload and boom we've got

25:36

a navbar so okay looking good now let's

25:38

modify this nav bar because I don't like

25:40

light nav bars so let's go ahead and

25:42

change that so let's head back over here

25:44

and go to our navbar.html and up here at

25:48

the very top where it says BG body

25:50

tertiary we can get rid of that

25:52

and instead let's type in navbar dash

25:56

dark and BG Dash dark so that will

26:01

change it from light to dark so if we

26:02

come back over here and reload boom I

26:04

think that looks much better so okay

26:06

let's play around with this let's

26:07

navigate let's modify this bar a little

26:09

bit more and we can start with this

26:11

navbar guide instead of it saying navbar

26:13

let's call Django CRM and instead of

26:17

pointing to hashtag let's point this guy

26:20

to

26:22

a URL tag pointing to our home page

26:27

all right okay let's go ahead and save

26:29

this and back over here hit reload all

26:32

right now if I right click and open in a

26:34

new window it goes to the home page

26:36

right we can click it forever and it

26:37

just keeps going to the home page so

26:38

that looks good next let's get rid of

26:41

the search thing I don't think we're

26:42

gonna need that

26:43

come down here to the bottom of our nav

26:45

bar and see this search come up until

26:48

let's see yeah you see you can click on

26:50

form in the closing form tag appears

26:53

that's how you know kind of you know

26:54

what to delete so you just highlight and

26:57

delete it save it come back over here it

26:59

reload all right that's gone next let's

27:01

get rid of this disabled link same deal

27:03

just come back over here and kind of

27:05

look for the word disabled there it is

27:07

go up above click on this Li the closing

27:09

Li tag highlights you can see there's a

27:11

little line underneath it so that's

27:13

again how we know what to delete

27:15

save that and I like to do one little

27:18

thing at a time to make sure I didn't

27:19

mess something up so we've got this drop

27:21

down thing we don't need that so again

27:24

let's head back over here look for the

27:25

word drop down ah there it is and then

27:27

come up see we don't even really need to

27:29

know HTML we could just sort of eyeball

27:31

this and when I click on this Li this

27:33

closing Li tag way down here highlights

27:36

so I know

27:37

all of this can go

27:39

save that and back reload all right and

27:43

now we've got these links we are going

27:44

to need some links up here so I want to

27:46

use this one and not this one I just

27:48

like the the look of the sort of

27:51

more muted one right there so let's get

27:54

rid of this home link instead again come

27:56

back here look for the word home there

27:58

it is click on the LI tag Right Above It

28:00

the closing tag highlights

28:02

we can get rid of it save it

28:05

come back over here boom all right we're

28:08

good to go so we are moving right along

28:10

we've got a functioning website we've

28:12

got a home page we've got a nav bar

28:14

things are starting to come together now

28:15

I think we want to add the ability to

28:18

register as new users log in and log out

28:21

so I think we'll look at logging in and

28:23

logging out first and then we'll do

28:24

registration that's a little bit more

28:26

complicated there's a little more stuff

28:27

involved logging in and logging out is

28:29

relatively simple and that's because

28:31

we're going to use the Django

28:32

authentication system this comes with

28:34

Django it will do all of the heavy

28:36

lifting for you it will take care of

28:38

logging people in logging people out

28:40

keeping track of who's who and what's

28:42

what and it just comes with Django and

28:43

it's really easy to set up and use so

28:45

we're going to do that now

28:51

so let's head back over to our code

28:54

and let's close out some of these things

28:56

just because so we need to import the

28:59

Django authentication system into our

29:00

app so let's come up here to the top of

29:02

our views.pi file and let's go from

29:05

django.contrib dot auth short for

29:08

authentication we want to import several

29:11

things first authenticate

29:14

then also log in and log out and while

29:18

we're at it we want the ability for

29:20

Django to flash up little messages on

29:21

the screen so like when somebody logs in

29:23

we want to flash up a little message

29:24

that says you have logged in you know

29:27

when it logs when you log out we want to

29:29

flash up a little message that says

29:30

you've logged out see ya whatever when

29:32

we register we want to flash up a

29:34

message that says you've been registered

29:35

successfully whatever all that good

29:38

stuff so we need to import that too so

29:40

let's go from

29:42

django.contrib we want to import

29:44

messages plural

29:47

and that looks good so we've already got

29:50

a user we set up a super user and if we

29:52

come back over here we can go to the

29:54

admin section of Django and we can log

29:57

in with that user right so we don't need

30:00

to register that user we've already got

30:02

it so we can log that user in and out so

30:05

I'm going to go ahead and log out but

30:07

that's why we can do the login and log

30:09

out stuff before we set up the

30:11

registration because we've already

30:12

registered a user now what you're going

30:14

to want is to be able to register users

30:16

on the web page not on the back end like

30:18

we did when we set up the super user way

30:20

back at the beginning of this thing so

30:22

we'll build all that out in a little bit

30:24

but we're going to start like I said

30:25

with logging in and logging out so

30:27

what we need here is a couple of

30:31

new views so I'm going to Define login

30:34

underscore user I want to pass in the

30:37

request

30:38

and for now I'm just going to say pass

30:40

and we want to Define log out underscore

30:43

user again we want to pass in the

30:45

request

30:46

and if you're not familiar with what a

30:48

request is anytime you go to a website

30:50

you're requesting that website you're

30:52

requesting that web page that request

30:55

gets sent back into the back end right

30:57

here and we pass it into the view and

31:01

then return something in this case we're

31:03

returning the home page so that's what

31:05

this request is you see a request a lot

31:07

in Django and just think of it as that

31:09

somebody going to a web page and

31:10

requesting that web page right so that's

31:12

all that is so okay we've got these two

31:15

new views we also need URLs because like

31:17

I said it's always a three-step process

31:18

in Django you need a view you need the

31:20

thing you know like that and you need a

31:23

URL so let's head over here and create

31:25

our URLs open our urls.pi file and I'm

31:28

just going to copy this and paste it a

31:30

couple more times so let's create a

31:33

login

31:34

URL and this is going to point to views

31:37

Dot Login underscore user that we just

31:41

created in our views.pi file and let's

31:43

name this login

31:45

okay so that's good we also want to log

31:48

out

31:50

right and this is going to be views DOT

31:53

log out User it's very complicated right

31:56

log out user and we want to give this a

31:59

name of log out now the reason why I'm

32:02

calling this logout user instead of just

32:04

log out is because here we're importing

32:07

login and log out and these are

32:09

basically functions that will run so our

32:11

view can't be named log in because it

32:14

will conflict with this login thing it

32:16

can't be named log out because it will

32:18

conflict with log out so we you know get

32:21

around that by calling it login user

32:23

instead of just login so that's why we

32:25

do that so all right head back over here

32:27

this looks good go ahead and save this

32:29

now head back over to reviews.pi file

32:31

and I've created this login user

32:33

function and if you want to create a

32:35

separate login page you need that but I

32:38

think we're just going to add this to

32:39

the home page so what we want to happen

32:41

is if somebody comes to the home page if

32:44

they're not already logged in we want to

32:46

flash up a form that says login if they

32:48

are logged in we want that form to

32:50

disappear here and we just want to show

32:52

the database like the CRM list of all

32:55

the records but we don't want to show

32:56

those records unless you're logged in so

32:58

we will do this all on the home page so

33:01

let's head back over here and we can add

33:03

all this stuff in our home view so

33:06

before we do that let's add the form to

33:08

our home.html page just so we can see

33:10

what we're looking at here head over to

33:12

our home.html so and let's Center this

33:14

form in the middle of the screen so I'm

33:17

going to give this a div with a class

33:19

equals and this is going to be col Dash

33:23

md-6 and this is just pure bootstrap and

33:26

then we also want to give it a space and

33:28

then give it an offset Dash md-3 and

33:32

basically like I said this is just

33:34

bootstraps code that says Center

33:36

everything in the middle of the screen

33:37

so if we just save this and head back

33:39

over here and click reload

33:41

well we got rid of this login view so we

33:44

need to modify this very quickly head

33:47

back over to urls.pi file and we don't

33:49

actually need that guy anymore so we can

33:51

comment him out and for now we'll

33:53

comment this out because we haven't

33:54

built this out yet and I'll throw an

33:56

error so if we save this head back over

33:58

here now if we hit reload we can see

34:00

boom hello world is more centered than

34:02

it was before and that looks good so

34:05

let's head back over here to our home

34:07

page and let's start building this thing

34:09

out so there's a couple of ways to

34:11

create forms in Django you can create a

34:13

forms.pi file we'll do that later with

34:15

the registration you can also just hand

34:17

code it we'll do that for this I want to

34:19

do both of them in this little video

34:21

here so you can see both ways to do it

34:23

so here let's just change this to log in

34:27

and let's create a form and the method

34:29

we want for form is post anytime

34:31

somebody fills it out and clicks the

34:33

button it posts that to the server and

34:35

then we also want to give this an action

34:37

of

34:39

and this is going to be a Django URL

34:44

and we want to point it to home because

34:46

we want to send those back to the home

34:48

page right so then down here we can

34:50

close our form tag anytime you create a

34:52

form with Django you also need a csrf

34:55

underscore token that's a cross-site

34:58

request forgery token it helps your form

35:00

from getting hijacked by hackers so

35:02

that's just a requirement now let's

35:05

create a form and we're going to use

35:06

bootstrap for this so I'm going to head

35:07

back over to bootstrap and come up here

35:09

to forums and click overview

35:12

and let's just grab the first one it

35:14

doesn't really matter and we can head

35:16

back over here and paste it in and if we

35:18

save this and head back over to the

35:20

website and hit reload you see okay

35:22

that's looking good it's asking for an

35:24

email address and a password and the

35:26

password has these dots in it that's

35:28

good it also has this check me out thing

35:30

we don't need that so we can get rid of

35:32

that as well also this is crammed right

35:34

up here I'm going to put a little space

35:35

in there so I think uh that will be

35:39

better so right here I just gonna add a

35:41

line break and all right let's start to

35:43

modify this thing so let's come down

35:45

here and first things first this button

35:47

is primary colored blue I want to change

35:50

it to secondary so if we save this come

35:53

back over here hit reload boom now it's

35:55

gray I think that looks better it says

35:57

submit maybe you want it to say log in

35:59

you could just change this to login

36:02

and now let's get rid of this checkbox

36:03

so check me out

36:06

click this div the closing div

36:08

highlights so we know we can delete all

36:10

of that

36:12

save it head back over here

36:14

all right that's gone the password field

36:15

is fine uh but uh this needs to be

36:19

changed from an email address field to a

36:22

text field

36:23

so we can do that let's see first let's

36:27

get rid of this label we don't need the

36:28

label for the password thing and get rid

36:31

of this div it says we'll never share

36:34

your email address we don't need that

36:35

and let's also get rid of this label

36:38

that says email address and instead of a

36:40

type of email this is going to be a type

36:42

of text

36:44

right and we have a class of form

36:46

control but we don't need an ID so let's

36:48

get rid of that

36:50

and same thing here with the password

36:51

field we don't need the ID thing so

36:53

we'll get rid of that okay so these two

36:56

things do need some things they need a

37:00

name so this one will give it a name of

37:02

first underscore name

37:05

and let's give it some placeholder text

37:08

and let's say first name

37:12

all right same thing down here with

37:14

password we need to give it a name so

37:15

I'm going to name it

37:17

you guessed it password

37:20

right and also let's give this some

37:22

placeholder text

37:24

and this is going to be password

37:28

so let's save this come back over here

37:30

and hit reload and oh that looks much

37:33

better we've got this placeholder test

37:35

text that says first name when we click

37:37

it and start typing that disappears uh

37:40

here we can still type the password and

37:42

that looks good when we click log in

37:44

nothing happens because you know we

37:48

haven't done anything yet we need these

37:49

to be required though so if you don't

37:51

fill them out we need a little thing

37:52

that pops up and says hey fill that out

37:55

so we could just come over here and then

37:57

just type in required

37:59

same thing for this guy required

38:02

and bootstrap will take care of this for

38:04

us so now when we hit reload

38:07

we don't need to resend this if I click

38:10

log in it says hey please fill out this

38:12

field so if I enter a name and then

38:13

click login it says hey please fill out

38:15

this field so that looks good it doesn't

38:17

actually go anywhere so

38:20

uh maybe we'll give a line break above

38:22

that button too so I don't know I like

38:25

line breaks I like to space things out

38:27

that's just me

38:28

uh resend okay so I don't know maybe

38:31

that looks better whatever you could

38:32

also put a line break between these two

38:34

things if you wanted

38:35

whatever

38:38

um let's see let's just do it right here

38:42

save this

38:44

reload

38:47

whatever whatever you like you can play

38:49

around with that so okay that looks good

38:51

but it doesn't actually do anything and

38:54

really we only want to show this if the

38:55

person hasn't already logged in so how

38:58

do we determine if a person has logged

39:00

in or not well we can come up here to

39:02

the top and we can say if user dot is

39:06

underscore

39:08

authenticated right then

39:12

let's say H1 hello world

39:18

right

39:20

else

39:22

do all this stuff and then down here at

39:25

the bottom

39:27

we

39:28

need to end our if statement so let's go

39:31

ahead and save this come back over here

39:33

now if we hit reload nothing changes

39:35

right but if I go to the admin section

39:38

and log in

39:39

right

39:41

now I'm logged in now if I go back to

39:43

the home page it just says hello world

39:45

and that form disappears so that's

39:48

pretty cool that works I'll go ahead and

39:49

log out again

39:51

now when I go back to the home page it

39:53

shows the login form again so okay we've

39:55

got this form it doesn't do anything yet

39:57

so probably need to work on fixing that

40:00

so let's head back over here and go to

40:03

reviews.pi file and inside of our home

40:05

view let's create some logic let's say

40:08

check to see if logging in so if a

40:12

person is logging in they are posting

40:14

otherwise they're just going to the web

40:16

page in which case they're getting

40:18

they're getting the request right other

40:21

than posting a request so we want to run

40:23

some logic let's say if request that's

40:27

this guy right here

40:28

dot method

40:30

equals

40:33

host

40:35

we want to do something right remember

40:38

this method here

40:39

on our home page we set this form method

40:43

to post right so we're posting the form

40:45

whenever we submit it and here it's

40:47

saying hey are they is this request

40:49

method a post if so hey they're filling

40:52

out the form let's do some form stuff

40:54

what do we need to do well let's grab

40:56

whatever they just submitted so let's

40:57

create a variable called username and we

40:59

can get whatever they typed into the

41:01

form by calling request dot post and

41:04

then passing in username

41:08

why username because on the form we gave

41:12

this field a name of oh first name we

41:15

should probably name this instead

41:17

username there we go

41:20

yeah brain freeze and instead of having

41:22

placeholder text say first name let's

41:23

have it say use her name that looks much

41:26

better save this let's head back over

41:28

here and refresh this okay so now it

41:30

says username and password I don't know

41:31

what I was thinking right so

41:34

add background reviews.pi file so our

41:36

username is going to equal username and

41:39

then we want our password to equal again

41:41

request dot post and then use our little

41:45

square Brack brackets and pass and

41:47

password again y password well because

41:50

on our home page here this password

41:52

field we gave it a name of password

41:55

right

41:56

right there so that's what we're looking

41:59

out for on the back end here these guys

42:02

right here and then we're just going to

42:03

assign whatever the person typed into

42:05

the form into this variable called

42:07

username we're also going to assign

42:08

whatever they pat whatever they typed in

42:10

as their password into this password

42:11

variable so now we have their username

42:14

and password we can run some logic and

42:16

say hey

42:18

is this a real user is their password

42:21

correct should we log them in and uh how

42:23

do we log them in so let's um you know

42:27

authenticate

42:28

and we do that by calling I'm just going

42:31

to create a variable called user and

42:33

then this will call the authenticate

42:34

function which is this guy up here that

42:37

we imported and inside of here we need

42:40

to pass in our request as always and

42:43

then set the username equal to username

42:46

which is this guy right here which is

42:49

whatever they typed in as their username

42:51

and we also need to pass in the password

42:53

as password which again is you know this

42:57

variable right here which is whatever

42:59

they typed in as their password so all

43:01

right that's pretty simple there so now

43:04

let's run some logic and see did they

43:06

type in everything does everything look

43:08

good let's go if user is not

43:12

none

43:14

then we want to log them in right so log

43:17

in

43:17

and then we want to pass in request and

43:19

user now if everything checks out here

43:22

if the username and password is correct

43:24

it gets passed in here and they'll be

43:26

logged in and let's create a message

43:28

right so let's go message.success and

43:32

then as always we pass in our request we

43:34

do that a lot and let's say you

43:37

have been logged in

43:42

I don't know that looks good and then we

43:44

want to redirect them somewhere well

43:46

where do we want to redirect them let's

43:47

just redirect them to the home page so

43:49

let's go return

43:51

redirect

43:53

and then home now we don't have the

43:57

ability to redirect yet so I'm going to

43:58

copy this and come up here to the very

44:00

top of the screen and we need to import

44:03

the redirect function there so okay that

44:06

looks good and we're good to go now we

44:08

can create an error message we could say

44:10

hey if something with went wrong and

44:12

they couldn't log in let's create a

44:14

message so

44:16

actually this should be message as there

44:18

we go so messages

44:20

dot success and we want to pass in our

44:23

request and let's say

44:26

there

44:27

was an error

44:31

logging in

44:33

please try again

44:36

I like the dot dot dots I don't know

44:39

it's just me and then I guess we

44:41

probably send them back home again right

44:44

so okay now we still have this guy down

44:47

here and the reason why that is is

44:49

because this is all set up to work if a

44:52

user is posting so if they're posting

44:54

process that else we can come back here

44:59

and we just want to send them to the

45:01

home page because if they're not posting

45:03

that means they're just going they're

45:05

just getting that page and in which case

45:08

we just want to show them the page so

45:09

let's go ahead and save this head back

45:11

over here and let's play around with

45:12

this first I'll hit reload and I'm going

45:15

to type in just nonsense here and click

45:18

login and we didn't get an error how

45:21

come well we actually need to add that

45:23

to our base.html file so if we come back

45:26

here to our base.html file

45:30

and underneath our nav bar but probably

45:32

still in our container let's create some

45:36

logic here let's say if messages so if

45:40

there are messages

45:41

and right away I'm going to end our if

45:43

because I forget to do that a lot of

45:45

times otherwise

45:47

right so then inside of here let's

45:50

display the message so

45:54

let's go for message in messages so it's

45:58

plural and then again I'm just going to

46:01

right away end my four

46:05

and inside of here we could just type in

46:07

the message for now so let's go ahead

46:10

and save this and let's see if that

46:12

worked so let's type in some nonsense

46:15

click this it says there was an error

46:16

logging in please try again there's an

46:18

air logging in please try again so this

46:20

doesn't look great we want to format

46:22

this so let's head back over to get

46:23

bootstrap and come down here to

46:25

components and click on alerts and

46:28

here's a little alert looks good we want

46:30

one with a little X in it so we can

46:32

close it so I'm just going to keep

46:33

scrolling down until I find one with an

46:36

X in it

46:38

oh there we go I'm just going to copy

46:40

this code head back over here and inside

46:43

of here I'm just going to paste all of

46:46

this in

46:48

tap it over to make it look nice

46:50

okay now we don't want it to say holy

46:53

guacamole so I'm gonna get rid of that

46:55

and instead of that we just want

46:59

to type in the message

47:03

right

47:04

that's this for message and messages

47:07

type out the message so all right let's

47:09

go ahead and save this try this again

47:10

head back over here

47:13

type in some nonsense

47:16

there is an error logging in please try

47:17

again

47:18

looking good

47:20

we can now try to log in with our actual

47:22

username

47:24

our admin guy and it says you've been

47:26

logged in and now it says hello world

47:29

very cool and that's all there is to it

47:31

we can now log in

47:37

okay so let's Now log out head back over

47:40

our code and the first thing we need to

47:42

do is head over to our urls.pi file and

47:44

uncomment out this log out thing I'm

47:47

going to leave this guy in here just in

47:49

case you want to create a separate login

47:51

page if you do you'll uncomment this out

47:54

and then you'll just come back over to

47:56

your views.pi file and create a log out

47:59

a login user function and basically just

48:01

put all this code in that function but

48:03

we're going to keep it the way it is and

48:04

do this all on the home page I think

48:06

it's a little more elegant doing it that

48:07

way so okay now let's create our log out

48:09

user function so this is actually very

48:12

simple a lot easier than logging in and

48:14

to do that we just call the log out

48:16

function

48:18

and then pass in our request now we can

48:20

do that log out function because up here

48:22

we imported this log out function that

48:25

will do all the work for us so that's

48:28

all we really need but we should

48:29

probably make this look nicer so let's

48:31

give this a little message so let's go

48:32

messages dot success that's in a request

48:36

and let's say I don't know what you have

48:39

been logged out dot dot love the dot dot

48:43

dots right and again we can just

48:45

probably redirect to the home page so I

48:47

can copy this guy

48:48

and then paste it down so all right

48:50

that's all we need now we need to

48:52

probably add a link to this in the nav

48:53

bar so let's head over to our nav bar

48:56

and here's this link now we only want

48:59

the logout link to appear if a user is

49:01

logged in if they're not logged in we

49:03

don't want them to be able to log out

49:04

they can't log out they're not logged in

49:06

right so that's actually pretty simple

49:07

to do let's just do some logic here

49:11

so let's go if user dot is underscore

49:15

auth

49:18

so that means hey if they are logged in

49:21

then let's allow them to log out

49:24

right else if they're not logged in and

49:28

let me just very quickly end my if so I

49:31

don't forget

49:31

and I'm going to copy this link and

49:34

let's create another link inside of here

49:36

so if they're not logged in we want them

49:39

to be able to log in all right so now we

49:42

need to point these somewhere so we need

49:44

a Django URL tag and we want this to

49:46

point to log out

49:49

there we go and let me just copy this

49:52

guy come down here and this one will

49:54

point to home because if they're not

49:57

logged in going to the home page will

50:00

show the login screen right so we want

50:02

to point them to the home all right

50:04

let's go and save this head back over to

50:05

the website and hit reload see if that

50:07

worked and we get a logout link when we

50:09

click it it says you've been logged out

50:11

and it redirects to the home login

50:13

screen and now we get this login link we

50:17

can try some nonsense that doesn't work

50:20

hey there was an error that's what we

50:22

want to see we still see this login link

50:24

if we log in

50:27

the login link changes to a log out link

50:30

and we're logged in and we can log out

50:33

and we can log in and it's good fun

50:37

all right so I'm gonna go ahead and log

50:39

out because now we need to register and

50:42

registering is a little bit more

50:43

complicated than logging in and we're

50:46

actually going to create a Django Forum

50:48

to handle that for us with logging in we

50:50

built the form ourselves by hand and

50:52

that's fine when it's basic like this

50:54

but the registration form is going to be

50:56

more complicated because we wanted to be

50:58

able to do a sort of logic type things

51:01

like if they type in a password that

51:03

doesn't follow the password rules you

51:06

know your password needs to be so long

51:07

it needs to have letters and numbers and

51:09

special characters and so we need to be

51:11

able to account for all of that we need

51:13

to be able to ask for a password twice

51:15

when you're registering so you enter it

51:17

once then you have to enter it a second

51:18

time to make sure the two match up so

51:22

that it's you know you've written it

51:24

correctly so that's a little bit more

51:26

complicated than a basic form like this

51:28

guy right here on the screen so we're

51:30

going to create a Django form for that

51:32

and it'll take care of it all for us so

51:35

there's gonna be a little bit of copying

51:36

and pasting because it's a lot of code

51:37

but I'll give you a link to my GitHub

51:39

where you can just copy and paste it

51:41

straight from there and that should be

51:42

piece of cake so let's get started doing

51:44

that

51:50

okay so a registration and I should

51:52

mention before we get going you may not

51:55

want to add registration right uh if you

51:58

don't want sort of open to the public

52:00

then leave this part off you can always

52:02

add users by coming into your admin

52:04

section here coming over clicking on

52:06

users and then clicking add users and

52:09

then manually entering them right here

52:11

pick a username have a password boom

52:13

you're done now you could do that if you

52:15

want to open this sort of company-wide

52:17

or whatever and you want people to be

52:19

able to sign up on their own at the

52:21

website then you need to do this next

52:22

little section so totally up to you

52:24

whatever you're interested in with your

52:25

project here but I'll give you both

52:28

methods here that way and this regular

52:30

registration method so let's head over

52:33

to our code and create a registration

52:34

page so let's hit up our urls.pi file

52:38

and I'm just going to copy this guy and

52:41

instead of log out let's call this

52:43

register

52:44

and it's going to be views dot register

52:48

underscore user and let's call this

52:50

register

52:51

all right that looks good save that

52:54

head over to our reviews.pi file and

52:57

let's define register underscore user

53:00

pass in our request as always

53:04

and then let's come up here and grab

53:09

this guy and paste him in but instead of

53:13

home.html let's call this register.html

53:16

and we're good to go there so I'm going

53:19

to copy this and head over to our

53:21

templates directory right click and

53:22

create a new file file save as and call

53:25

this register.html

53:27

and let's open up our home page and grab

53:32

this stuff

53:34

and paste it in

53:38

and let's say H1 register just for now

53:42

and let's go back to our home page and

53:44

grab this guy because why type it when

53:46

we can copy and paste it all right okay

53:49

all right so let's save this and add a

53:50

link to this page in our nav bar so if a

53:53

user is authenticated if they've logged

53:56

in we don't want them to be able to

53:57

register because they've already

53:58

registered so this should go in our else

54:00

block right here and let's just copy

54:05

this guy

54:08

and let's put it another one in first

54:10

and instead of it saying login let's

54:11

have it say register and we want to

54:14

point this to URL register all right go

54:18

ahead and save this head back over to

54:19

the website and let's see if that worked

54:20

we want to log out

54:22

when we're logged out we see there's a

54:24

register link we can click on it and go

54:26

to this page if we log in

54:30

that register link disappears okay and

54:33

we're good to go so let's log back out

54:35

again head over to our register page and

54:37

now we need to build out this page now I

54:40

mentioned before we're going to be

54:41

creating a Django form for this we're

54:43

not going to be hand coding this so that

54:46

would be both easier and harder so let's

54:48

come over here

54:49

to our website directory right click and

54:52

create new file file save as and we want

54:54

to save this as forms dot pi and in our

54:57

forms.pi file we need to import a few

54:59

things so let's go from django.contrib

55:03

dot auth dot forms we want to import the

55:08

user creation form

55:13

and you notice the U the C and the f are

55:15

all capitalized here and the user

55:17

creation Forum does just what it sounds

55:19

like it creates users right it does all

55:21

the work for us so we also want to go

55:24

from django.contrib

55:27

Dot auth

55:29

dot models we want to import the user

55:33

model and the user model is what we've

55:35

been using up until now it's what

55:36

allowed us to create our super user what

55:39

we've been logging in and logging out

55:40

with that admin user that all gets saved

55:43

to the user model right and that just

55:46

comes with Django it's already set up we

55:48

just have to import it and that should

55:50

be good enough so let's create a class

55:52

and I'm going to call this sign up form

55:55

and this is going to inherit the user

55:57

creation form and that's just this thing

56:00

we just imported right

56:02

so we're saying hey use that form but we

56:05

want to modify it a little bit right so

56:07

what we want is to grab let's say

56:11

people's first name their last name

56:12

their email address now you may not want

56:15

to grab their first name last name and

56:16

email address but I I suspect you

56:19

probably do just because it's good stuff

56:20

to have and this is how you do it so

56:23

let's define those things we want email

56:25

we want first underscore name and we

56:28

want last underscore name now we're also

56:30

going to want username and password but

56:32

we'll deal with those separately in a

56:33

minute so first here this is going to be

56:36

a

56:37

forms.email field

56:40

now this forms

56:42

we don't know what this is so we need to

56:44

import it so from up here we go from

56:46

Django we want to import forms

56:49

and that will allow us to use all these

56:51

forms so we've got an email field we

56:54

also want a forms.car field for this and

56:58

also a forms.car field or this guy as

57:02

well and car field stands for character

57:04

Fields so characters and a name letters

57:06

email is just email addresses it allows

57:09

Django to do regular email address stuff

57:12

like if you don't type in at symbol

57:14

Django will know because it's using this

57:17

email field and it'll throw up a little

57:18

error saying hey that doesn't look like

57:19

a real email address try again things

57:21

like that right so that's cool now each

57:25

of these

57:27

we're going to give a label of nothing

57:30

because we're gonna use placeholder text

57:31

so we don't want to actually text above

57:33

or below the fields so we can give that

57:36

to each of these next we want to give

57:38

this a widget

57:40

of forms dot text input

57:44

and that'll basically say hey the form

57:46

field that shows up on the screen that's

57:48

a text input field it's just a text box

57:50

basically right and inside of this we

57:52

want to give it adders attributes right

57:55

and this will allow us to pass different

57:57

attributes onto the page to style our

58:00

form so we're going to be using

58:01

bootstrap to style our forms and

58:04

bootstrap requires a class of form

58:07

control so we can designate that right

58:09

here so let's go class and then a colon

58:13

and then we can just type in form Dash

58:16

control and that's it now we also

58:18

probably want to pass some placeholder

58:20

text so again we can pass in placeholder

58:22

right here

58:24

and then designate whatever our

58:26

placeholder text should be and this

58:28

should just say email address

58:30

right so okay that looks good so now I'm

58:32

going to copy this

58:40

and we're going to paste that again in

58:43

right here

58:45

but we need to modify it a little bit

58:46

before our widget we need to give this a

58:49

Max underscore length of something

58:54

right so this looks like a capital l

58:57

right here it's not it's a lowercase L I

58:59

promise you anytime you see an L that

59:02

kind of looks swoopy like that in

59:03

Sublime Text same thing with this label

59:06

here this L there and that L and that L

59:09

those are all lowercase L's Sublime just

59:12

does that it makes it look weird like

59:14

that it confuses a lot of people they

59:16

think that's a capital l it's not it's a

59:17

lowercase L anyway we want to give this

59:19

a max length and I misspelled length

59:23

length there we go of I don't know say

59:26

100.

59:28

right

59:29

a person's first name shouldn't be more

59:31

than 100 characters long right you

59:33

should you could probably make it 50. it

59:35

doesn't really matter I'll just leave it

59:36

like that uh here again text input we

59:40

also want adders with form control for

59:42

the placeholder text here though we

59:44

should probably change this to first

59:46

name

59:47

that looks good

59:49

now I'm going to copy all of this and

59:54

paste it in again right there and this

59:57

one will say last name

60:00

okay that looks good so I know this is

60:03

all kind of scrunched up on the screen

60:04

maybe it's hard to read I'll give you a

60:05

link to all of this code uh in my GitHub

60:09

repository you can check that out after

60:11

this little section here we'll push our

60:13

code up to GitHub so that you can sort

60:16

of see it if you you know want to copy

60:18

and paste this stuff or look at it in a

60:21

web browser so okay that looks good

60:22

there now we also need to give this a

60:24

class with a meta of and we need to set

60:27

the model

60:29

so our model is going to be a user

60:31

because we imported that right up here

60:33

right we also need to designate the

60:36

fields in our form so they're obviously

60:39

going to have these three fields we also

60:41

want to designate username password one

60:43

and password two and remember we need

60:46

two sets of passwords so that we can

60:48

compare the two to make sure the user

60:49

isn't typing a typo or something it's

60:52

just a basic security precaution so here

60:54

we want to designate a username

60:57

we want to designate a first underscore

61:00

name we don't want to designate a last

61:03

underscore name

61:04

we want to designate an email address

61:08

and then we want to designate password

61:10

one and password two and Django

61:15

expects password 1 and password two so

61:18

you gotta have them both right so okay

61:20

that looks good

61:22

so we're halfway done now now we need to

61:26

copy and paste a few more things and I'm

61:28

just going to paste all this code in

61:31

and

61:33

the first thing I want to do is

61:36

tab all of this stuff over because

61:38

sometimes when you copy and paste the

61:40

tab gets a little out of control so you

61:43

want to make sure these have been all

61:45

tabbed properly so you can do it

61:48

manually each one like this and I'm just

61:50

using the tab button on my keyboard to

61:52

make sure that everything is tabbed

61:54

correctly even though it looks like it's

61:57

tabbed like it may

61:59

look like this see these dots that means

62:02

spaces have been used instead of tab

62:04

sometimes that happens when you copy and

62:06

paste things it doesn't look like it did

62:08

here but I just want to make sure so I'm

62:11

going to do that so what do we got here

62:13

well we are basically doing the exact

62:16

same thing we did here but we're doing

62:18

it down here for our username our

62:21

password one and our password two and

62:24

that just allows us to add whatever we

62:26

want in this case our adders our class

62:29

of form control as well as our label of

62:32

nothing so if you look through here

62:34

you'll see we've got username class

62:37

form control widget adders placeholder

62:41

right the label is nothing and also this

62:43

help text the help text is I mentioned

62:46

this a little while ago if you mess up

62:48

somewhere if you don't type the right

62:50

thing in a field this is the little help

62:52

text that will pop up and you know says

62:54

uh if we can look at here like the

62:56

password thing here it says hey your

62:59

password can't be

63:01

uh let's see let me pull this back your

63:03

passwords can't be too similar to the

63:05

other personal information your password

63:06

must contain at least eight eight

63:08

characters your password can't be too

63:10

commonly used password your password

63:12

can't be entirely numeric and these are

63:15

just different things that can pop up

63:17

and Django will pop them up as needed

63:19

but they have to be designated here just

63:21

to make them look good using bootstrap

63:25

right so like I said I'm just gonna

63:27

leave all this here you can copy and

63:29

paste it from my GitHub account we'll

63:31

look at that in just a minute I'll show

63:33

you where you can find that I don't want

63:34

to type all this stuff out it would take

63:36

forever and you don't either so you're

63:38

going to want to copy and paste this

63:39

this stuff here just initializes all of

63:41

this stuff it's basic python class stuff

63:44

these are double underscore so

63:46

underscore underscore right there's no

63:48

spaces here or here that messes up

63:51

people sometime and you'll notice we're

63:53

passing in the sign up form which is

63:55

this guy here this sort of allows us to

63:57

take all of this stuff and all of this

63:59

stuff and kind of mush them together and

64:01

output them onto the screen so okay I

64:03

think that looks good before we move

64:05

forward let me just push all this code

64:06

to GitHub and point you in the right

64:08

direction in case you want to copy and

64:10

paste this stuff which you probably will

64:11

let's head back over to our terminal hit

64:13

Ctrl C to break out of the terminal and

64:16

let me just add all this stuff to my

64:18

GitHub repository so get add period get

64:21

commit Dash am and let's just say

64:24

registration

64:26

we've done more than that but good

64:28

enough and then get push

64:33

all right now I'm going to turn our

64:36

server back on so that's running

64:39

now let's head over to github.com

64:41

forward slash flat planet and no I do

64:45

not think the world is flat I just find

64:46

it hilarious that some people do so

64:48

that's what my account is and you can

64:51

click on this Django CRM Link in

64:53

repositories or you could just go to

64:55

github.com forward slash flatplanet

64:57

forward slash Django Dash CRM the

65:00

capitalization is important so get that

65:02

right and then just click on website and

65:05

let's see forms.pi where is that

65:09

ah there it is

65:11

and here's all that code so you could

65:13

just you know copy it right out

65:16

right click copy paste it in boom you're

65:19

good to go so okay that's good now we've

65:21

got all this stuff we need to sort of

65:23

put it into the web page so let's head

65:27

back over to reviews.pi file and we need

65:29

to import that form that we just created

65:31

so let's come up here to the top and

65:33

let's go from dot forms we want to

65:36

import our sign up

65:39

form and it's sign up form because on

65:43

our forms.pi file here we named it sign

65:46

up form right there so notice the

65:48

capitalization capital S capital u

65:49

capital F that has to be the exact same

65:54

right here

65:55

so all right that looks good now we can

65:58

come down here to our register user View

66:01

and we start playing with this so like

66:03

with our login

66:05

right when somebody fills out this thing

66:08

they're going to be posting it so we

66:10

could just copy that right here if

66:12

request that method equals post then our

66:15

form is going to equal the sign up form

66:19

and we want to pass in the request dot

66:22

post

66:25

so we're basically saying hey whatever

66:26

they filled out in that form send it

66:28

over to our sign up form and do

66:30

something so what do we want to do well

66:32

first we need to figure out

66:34

is what they typed in valid right so

66:37

let's go if

66:39

form dot is underscore valid

66:43

and Django is doing all of this stuff

66:45

for us behind the scenes so we really

66:48

don't even care what most of this stuff

66:50

is so if it is if the form is valid then

66:54

we just want to save it so form dot save

66:57

and

66:59

what is the form that's this guy right

67:01

here which is our sign up form we just

67:03

want to save it right so now that the

67:05

form has been saved you know when

67:08

somebody fills out a registration form

67:09

they usually want to fill out the

67:11

registration form because they want to

67:12

use the site they want to log right in

67:13

and start using it so let's log them in

67:15

right now so let's uh authenticate

67:20

and log in so let's grab their username

67:24

and that's going to equal form dot

67:27

cleaned underscore data

67:30

and we want to pass in username this is

67:33

just

67:34

this form.clean data takes whatever they

67:37

posted on the form and pulls out the

67:40

username and assigns it to this username

67:42

variable we also want their password

67:44

so that's going to be form.cleaned

67:46

underscore data

67:48

and then password one right because on

67:52

the form on the website it will be

67:54

password one because let's see in our

67:57

forms.pi file

67:59

that's what it's called there right

68:01

so now once we have their username and

68:03

password we can try to authenticate them

68:04

so let's go user equals and again we

68:06

want to call authenticate and we want to

68:09

pass in the username equals username

68:12

and the password equals password

68:16

why password and not password one

68:18

because we took password one and we

68:21

assigned it to this variable called

68:22

password so that's what gets passed in

68:25

there

68:26

okay so once that's been done we can log

68:29

them in so let's log in we want to pass

68:31

in the request and we want to pass in

68:33

that user so if it was successful we

68:37

want to give them messages Dot

68:39

success

68:41

and we want to pass in the request and

68:43

let's say you have

68:47

successfully

68:51

registered

68:52

welcome whatever and then we want to

68:56

redirect them somewhere so let's go

68:58

return redirect and let's send them to

69:02

the home page right

69:04

so again this is if they're filling out

69:07

the form if they're posting the form if

69:09

they're not posting the form that means

69:11

they're just going to the website so

69:13

else now we still need that form

69:16

so let's set the form equal to our sign

69:19

up form you'll notice up here we passed

69:22

in the request here we're not passing in

69:25

the request because they haven't filled

69:27

out the form right they're just going to

69:29

the page they want to fill out the form

69:31

they haven't done it yet so we don't

69:33

have to pass in that post right right so

69:36

we do need to pass this form onto the

69:39

page so we could do that

69:42

inside of this

69:45

context dictionary so we put quotation

69:47

marks form colon form now notice this

69:51

has quotation marks this does not so

69:53

this will pass the form into the web

69:56

page our register.html page and then we

70:00

can do something with it right so let's

70:02

do something with it so let's head back

70:03

over to our register.html file and let's

70:06

add a little line break here and I'm

70:08

going to come back to our home page

70:10

where did that go there it is and let's

70:13

see I'm going to grab this guy so let's

70:18

come right up here and before I forget

70:20

let's close that div

70:22

and you know what we can also grab

70:25

this stuff as well

70:30

we'll grab that and we need to close our

70:32

form tag we also need a submit button so

70:35

let's grab this guy

70:40

go oh it looks like we've closed our

70:42

form tag twice we don't need that

70:44

all right uh back over here

70:48

boom

70:50

instead of it saying login let's have it

70:52

say register

70:54

okay and we also don't need that there

70:57

what is going on

70:59

we don't need two forms get rid of that

71:02

on the home page okay and that looks

71:06

good there head back over here all right

71:08

this looks good so we don't need to

71:09

point this to the home page we could

71:11

just take that out if we leave it out it

71:13

will post to itself so you don't really

71:15

need that so that's fine we need our

71:18

csrf token now we need to add the actual

71:20

form and to do that we just type

71:23

form dot as underscore P so if we save

71:27

this head back over here and hit reload

71:30

boom we get this very cool form now I'm

71:34

going to copy and paste some more code

71:36

here very quickly that you can find in

71:38

my GitHub account if you want it

71:40

but above this right below the csrf

71:42

token I can paste in if there are form

71:44

errors then this is a little div with an

71:47

alert it looks just like if we go over

71:50

to our base.html file there we go this

71:53

is the same code we grabbed from

71:56

bootstrap earlier it posts the messages

71:58

up on the screen right

72:00

uh back to our register page it just

72:03

does that same thing here and if there

72:05

are errors it says your form has errors

72:07

and then it Loops through here and it

72:08

puts out whatever error is on the form

72:10

right so that's kind of good to have

72:14

so I'll leave that in here you can copy

72:16

and paste it from my GitHub if you want

72:18

or you just leave it out it doesn't

72:20

really matter all that much but we're

72:22

good to go so if we come back over here

72:23

and hit reload we see we've got this

72:25

thing now if I click on this it says oh

72:27

you got to fill this out so let's give

72:28

this a try so let's create a username

72:30

I'm going to call this uh John and now

72:32

this is case sensitive so you'll have to

72:34

log in with capital j o h n in the

72:36

future so this is going to be John Elder

72:39

my email address is John

72:42

e4196 gmail.com my password is that and

72:48

if I click this again it says hey you

72:50

got to fill out that field now I'm just

72:52

going to type in garbage here so these

72:53

won't match and we get an error because

72:55

our views

72:57

uh head back to reviews.pi file and at

73:00

the beginning at the very end of our

73:01

registered user let's copy this and we

73:04

need to paste it in again so this will

73:06

that should take care of that let's save

73:08

this head back over here give this

73:11

another try

73:12

um now we get a little pop-up so I'm

73:14

going to type in my password let's try

73:16

this again gibberish here

73:19

now it says your form has error to

73:20

password field the two password Fields

73:22

don't match so that is

73:25

uh let's go back to

73:27

register.html that's this thing right

73:29

here in action so all right that looks

73:31

like that works that's pretty cool so

73:34

now let's actually register I'll type in

73:36

correct passwords here

73:38

click register boom you successfully

73:40

registered welcome and I can now log out

73:44

so let's now try and log in John

73:50

you have been logged in hello world now

73:53

if I log out and I go to my Dash admin

73:56

section and I log in as admin

74:00

and I click on users I'll see there's

74:03

John and there's admin

74:05

uh you'll notice admin is a staff user

74:08

he's got a little check mark John is not

74:10

John's just a regular user that signed

74:11

up on the website they can't log into

74:14

this section this admin section if

74:17

they're not a staff user thing so okay

74:19

very cool I'm gonna log out here head

74:21

back over here and we are good to go so

74:24

that is registration

74:26

and we'll notice if we log in again with

74:29

say John

74:31

our register link disappears our login

74:33

link disappears all we have is a link to

74:36

log out which is what we want or we can

74:38

go back to the home page which is again

74:39

what we want and we're good to go so all

74:43

right we are moving right along I think

74:44

the only thing left to do now is

74:45

actually set up the CRM stuff up until

74:48

now this has just been playing around

74:49

getting the website up and running we

74:51

want to now actually add in the ability

74:53

to save and view records to update them

74:55

to look at them to do all the fun things

74:57

and I think it's time and I'll start

74:59

doing that

75:04

so to set up database stuff the first

75:07

thing we need is a model so let's head

75:09

over to our models.pi file and this is

75:12

where we Define our model now like I

75:14

said earlier it really does not matter

75:16

what database you use the code here will

75:19

always be the same we're not writing SQL

75:21

code here we're not writing postgres

75:22

code here we're not writing sqlite 3

75:25

code here or MySQL code here this is

75:27

Django code it's just pure python that

75:30

creates a class that will then abstract

75:33

away and create that code for us on the

75:36

back end it will create the MySQL code

75:39

if you're using MySQL it will create the

75:41

postgres SQL code whatever database

75:43

you're using it will do it for you

75:45

behind the scenes and that's the great

75:47

thing about using Django so

75:49

um let's just dive in here and Define

75:51

our class so let's come down here and

75:53

let's create a class and what do we want

75:55

to call this I'm going to call this

75:56

record now you're going to say we're

75:58

saving records shouldn't it be records

76:00

no Django will pluralize it for us so

76:02

I'm going to call it record uh anything

76:05

you want if it's customers maybe you

76:07

would call it customer whatever and we

76:09

want to inherit model dot model

76:12

right and again this is a lowercase l so

76:15

is this which you know looks like

76:18

Capital but it's lowercase so now we

76:20

just Define the things we want so the

76:22

first thing I want is a created at field

76:25

and this is just going to add a little

76:26

time stamp for us so to do that we'll

76:28

call models

76:30

dot date time field and we just want to

76:34

set auto underscore now

76:38

underscore add and set that equal to

76:40

true so Django will just anytime we

76:43

create a new record it will just slap a

76:45

timestamp on there of when it was

76:47

created just automatically and keep

76:49

track of that for us if we ever want to

76:52

know when a record was created sort of

76:54

useful I always do that for almost every

76:56

model I ever create because even if

76:58

you're not going to use it you might

76:59

someday want to know when a record was

77:01

created and it's just a really easy way

77:03

to do it automatically so now let's

77:06

designate what we want to save we

77:09

definitely want to save a first name

77:12

we probably want a last name

77:16

let's go address

77:19

and then City

77:21

state

77:23

zip code

77:25

you know whatever you want if you wanted

77:27

their email you could do email

77:29

leave that off

77:31

um

77:32

if you wanted well let's let's put it on

77:34

let's be crazy email equals and phone

77:37

equals and maybe we'll put

77:40

these two up higher right after last

77:44

name maybe so we've got a fair amount of

77:46

stuff here right so what do we do now

77:49

well we need to designate what these are

77:50

going to be so this is going to be a

77:52

models.car field and again that stands

77:55

for character field and we want to set

77:57

the max underscore length

77:59

to I don't know what's let's say 50

78:02

right so I'm just going to copy this and

78:05

again this is a lowercase L I know it

78:08

looks Capital but uh it's not so let me

78:11

just pop all of this stuff in here now

78:13

we can change these Max lengths for

78:15

instance maybe your email address might

78:17

be a little bigger put that at 100 it

78:20

really shouldn't be uh a phone number is

78:22

like area code three digit code

78:27

and maybe there's a one so I mean I

78:30

don't know that at 15 or something that

78:33

should be fine your address I don't know

78:35

maybe 100 City characters are never

78:39

longer than 50 state is more like

78:41

probably what

78:43

yeah 50 unless you're doing like

78:46

abbreviations like NV for Nevada IL for

78:50

Illinois but ah we'll leave it at 50.

78:52

and the zip code I don't know let's put

78:54

that at 20. now some people want to do

78:57

like number fields for zip codes but I

78:59

leave it at care as car field because

79:01

you're never going to do math on a zip

79:04

code even though a zip code is a number

79:06

in some countries zip codes have letters

79:09

in them too right so I don't know in

79:11

Canada I think it's like 26 H 597 or

79:15

something you know same thing in grade

79:17

Britain a lot of countries use uh

79:19

letters in zip code so we're gonna leave

79:21

that as car field so that's pretty much

79:24

it now we can Define

79:26

underscore underscore Str underscore

79:30

underscore pass in ourself

79:33

and then here we can just return

79:36

what we want to show on the screen if we

79:39

just access one of these records so I'm

79:41

going to create an F string

79:43

and inside of here I'm going to pass

79:45

self DOT first

79:47

underscore name

79:50

and we'll do it again and we'll go self

79:53

dot last underscore name so if you just

79:56

call one of these records

79:58

in the admin area or on a web page it

80:01

will return the first name and the last

80:02

name right so that's good that's a good

80:04

enough representation for us for now and

80:07

uh that should be good so go ahead and

80:09

save this and this is it this is all you

80:11

have to do to create a database model in

80:14

Django you don't need to know any SQL

80:16

Django will take this and convert it

80:19

into the SQL but to do that we need to

80:21

make a migration and push that migration

80:23

into the database and we did a migration

80:25

way back at the beginning of this course

80:27

because Django by default has some

80:29

database stuff that needs to be pushed

80:31

into the server into the database

80:33

migrated into the database and we did

80:36

that using the migrate command watch

80:37

back to the beginning of this video to

80:39

see that again we need to do that again

80:41

but first we need to make a migration so

80:43

let's head back over to our terminal and

80:46

we're getting oh we got an error it

80:48

looks like here on line four which uh

80:51

yeah this should be

80:53

models.model right here

80:56

is up here at the top we're importing

80:57

models so models.model save that that

81:00

looks good always nice to check in with

81:03

the terminal before we get going and

81:04

okay it looks good now now Ctrl C to

81:07

break out of our server and let's create

81:09

a migration let's go python manage.pi

81:12

make migrations and this is plural we're

81:16

making one migration but the command is

81:18

still migrations uh so keep that in mind

81:21

hit enter and boom it's created a

81:23

migration and we can look at this

81:24

migration if we want it's zero zero one

81:26

underscore initial dot pi and it's in

81:29

our migrations folder so if we head back

81:31

over here and here's our migrations

81:33

folder if we open it boom yeah sure

81:35

enough there it is here's our migration

81:37

and this is what Django has done it's

81:39

taken the stuff from our models.pi file

81:41

all of this stuff and it's created

81:43

a migration

81:46

and you'll notice here's our created at

81:48

first name last name email phone address

81:50

city state ZIP it's also given us an ID

81:54

now this is very useful Django does this

81:56

automatically as well it assigns a

81:58

primary key to each record so it will

82:01

take care of all that for us we don't

82:03

need to Auto increment anything we don't

82:05

need to designate something as the

82:07

primary key that's what this ID field is

82:10

and you'll see it kind of tab over here

82:14

it's set as the primary key right so

82:17

that's really cool and that's pretty

82:20

much it this is our migration so now we

82:23

have this migration we need to push it

82:25

into the database into our mySQL

82:27

database and we do that on the terminal

82:29

we just go python

82:32

manage that pie migrate

82:35

which we did this command earlier at the

82:37

beginning of the video with that initial

82:39

migration and boom it's done so you

82:42

could probably look at this in the MySQL

82:44

workbench

82:45

if you want you can come over here to

82:47

elderco and click refresh

82:50

and you'll see

82:52

website record

82:55

now exist in our table

82:57

right

82:59

and if we click on it we see it has the

83:01

created at first name last name email

83:04

phone address city state and zip code

83:06

very cool boom done right that's all

83:09

there is to it so very very cool and we

83:12

can now start using this thing and

83:15

to do that let's head over here to our

83:17

admin section and log in there just to

83:20

see and oh gotta turn server back on

83:23

so python manage.pi run server

83:29

okay now when we head back over here hit

83:32

reload we can log into the admin section

83:34

and you would expect to see that new

83:37

records model listed here but it's not

83:40

we have to actually add it so we can do

83:41

that really easily just come over here

83:43

let me close this migrations folder and

83:47

we want in Min dot pi and from here we

83:50

just need to import that model that we

83:51

created so let's go from dot models

83:53

import record

83:55

right and that's because our models.pi

83:57

file we called that record right so from

84:01

dot models models.pi import this record

84:04

right there we go and then we need to

84:07

register this on the admin section of

84:09

the site so we just go admin Dot site

84:12

dot register and pass in that record

84:16

save this head back over to the website

84:18

hit reload and boom now our records pops

84:21

up and you'll notice it's records it's

84:23

pluralized it like I said it would and

84:25

so if you named it records when you

84:27

created the model it would be records

84:31

with two s's right

84:33

which is weird but that's why we only

84:35

put it as record in the model when we

84:37

created it so we can click on this guy

84:39

and you can see there's no records right

84:41

now I just want to manually add a couple

84:42

so we have something to work with pretty

84:44

soon here we'll create a form on the

84:46

website where you can add them there but

84:48

for now I'm just going to create a

84:49

couple so let's say first name John

84:50

Elder say John at elder.com that's not

84:54

real one on one two two two three three

84:57

three three my address says 10 West

84:59

Elder Street uh Las Vegas

85:04

Nevada

85:06

89137 we can click save and boom there

85:10

it is so if we go back to this main

85:13

thing click on records again there's

85:15

John Elder very cool so let's add

85:18

another one just we'll just add two for

85:20

good measure and this is going to be

85:21

Mary Smith

85:23

her name her email is Mary at smith.com

85:28

her phone is six seven seven seven seven

85:30

six six six five five ah whatever her

85:34

address is uh 27 Mary way right in

85:39

Chicago Illinois 60610

85:43

whatever fake data and there's Mary

85:46

Smith

85:47

so very cool

85:53

now we want to be able to view these

85:55

things from the website so let's head

85:58

back over to the website I'm still

86:01

logged in as admin and we want these to

86:03

show up on the home page when a person

86:04

is logged in we don't want this stuff to

86:06

show up if they're not logged in but if

86:09

they are we want to show up there so

86:10

let's head over to our code and start to

86:12

build this all out so let's go to

86:15

reviews.pi file and let's play around in

86:17

our home view right here so let's well

86:20

first we need to import that model up

86:22

here at the top so let's go from dot

86:24

models we want to import record

86:27

right so right at the top of our home

86:29

view let's grab all of the records that

86:31

are in the table right now so I'm going

86:33

to create a variable called records

86:35

and this is going to be a record

86:38

dot objects

86:42

dot all so this will just grab

86:44

everything in the table and assign it to

86:46

this records variable now we can pass

86:48

that in to our web page right so let me

86:53

copy this and let's come down here

86:55

this stuff is still if a user is posting

86:58

We don't want to mess with that but if

87:00

they're not posting the form to log in

87:01

it means they've already logged in and

87:04

we want to view the page so here we'll

87:06

just pass in records colon records

87:10

all right so let's go ahead and save

87:11

that and now let's head over to our

87:13

home.html file where'd that go there it

87:16

is

87:18

and we've already got this set up to

87:20

where if they're authenticated we want

87:21

to say hello world instead of that let's

87:24

say uh Records for now we'll probably

87:26

get rid of that but for now let's just

87:28

say that

87:29

and let's run some logic

87:32

so let's go if records

87:35

if there are records we want to do

87:37

something and right away I want to end

87:39

my if so I don't forget now what do we

87:42

want to do well

87:43

we likely have lots of Records we're

87:46

pulling everything out of the database

87:48

there's probably more than one right we

87:50

would expect so let's Loop through them

87:52

all and put them on the screen so let's

87:55

say for record in records

88:00

and again right away I'm gonna end my

88:04

four because if I don't I'll forget now

88:06

where's this records coming from well

88:09

that's just this thing right here that

88:11

we passed onto the screen which is

88:13

actually

88:15

this thing which is all of the records

88:18

from the database table right that we

88:21

just created from our model so okay so

88:24

for record and Records let's just print

88:26

out

88:27

the record

88:29

and we can

88:31

give a little line break here

88:34

between each one

88:36

and okay so let's

88:38

see what this looks like so let's hit

88:40

reload and we see John Elder and Mary

88:42

Smith why is it only putting John Elder

88:45

and Mary Smith where's the rest of the

88:47

stuff well you'll remember right back

88:49

here where we defined our model that's

88:52

this stuff right here we've told it only

88:54

to return first name and last name if we

88:57

just call the record so if we call a

88:59

record it's going to return first name

89:00

and last name all the rest of the stuff

89:02

is in there it's all packed in there we

89:04

just have to pull it out explicitly if

89:06

we want which is what we want to do

89:07

right you don't want to spill out

89:09

everything like this so to grab each

89:12

specific item we would call record dot

89:16

whatever so record DOT first underscore

89:19

name

89:21

and

89:23

let me just come through here and make a

89:26

few of these so this would be a record

89:29

dot last name

89:32

and I'm just gonna paste a bunch of them

89:34

in here and just look at our model these

89:36

are the things so next is email

89:41

let me close some of these so

89:45

this will be a record email then we want

89:48

phone

89:50

probably and you could put these in any

89:53

order but I'm just gonna go through and

89:55

put them in the order we have them here

89:57

uh let's see this is gonna be address

90:02

then City this is very exciting work and

90:06

copy paste copy paste City

90:09

state

90:12

and finally zip code

90:18

we could also do

90:21

let's see what else we have we also have

90:23

created at we can output that if you're

90:25

curious to see what that is we also have

90:27

an ID because Django automatically

90:29

creates an ID so let's go ahead and save

90:31

this and see now I put these on multiple

90:33

lines but in reality the HTML is going

90:35

to print it all out on one line

90:38

and we see sure enough there it is John

90:40

Elder John elder.com

90:44

Mary Smith same deal so this is hard to

90:48

read

90:49

even with a couple extra line breaks

90:51

here

90:53

still hard to read what we really want

90:55

here is a table that you know looks nice

90:59

and we can click on and do things so

91:01

let's look at that

91:06

and to do that we're gonna head back

91:08

over to bootstrap and bootstrap has

91:10

something called tables and I'm just

91:13

gonna search for table there it is it's

91:16

in the content section so click on

91:17

tables

91:18

and here are all the different table

91:21

options so to create a table in

91:23

bootstrap we just need to copy this

91:24

stuff so I'm going to copy

91:27

let's see actually let's grab all of

91:30

this so we want the table we want the

91:33

head which is this first row and each of

91:36

these things are each of these columns

91:37

and then we want a table body and a TR

91:41

so that looks good we're gonna have to

91:43

Tinker with this so let's go right here

91:47

and paste all this in

91:49

there we go uh we also need to close all

91:52

those things so let's come down here to

91:54

the bottom and grab those closing tags

92:00

and we'll just paste all that in

92:03

okay

92:05

maybe tap that over

92:07

so this is our table head and so the

92:12

first thing is going to be name

92:14

and we'll smush the first and last name

92:17

together for one name and then after

92:20

that it's going to be email

92:23

then phone

92:26

then address and we're going to need a

92:30

few of these so

92:35

after address is City

92:39

then state

92:42

and zip code

92:45

then we probably want the created at

92:48

maybe

92:49

and then ID

92:53

so let's save this and just refresh to

92:55

see if that looks okay

92:59

and we're getting smooshed in here so

93:01

we'll we'll have to play around with

93:02

this a little bit

93:04

for instance I guess we don't really

93:06

need this offset

93:08

centered thing so I'll take I'll take

93:11

that out

93:12

and that out

93:15

so now okay stretching all across that

93:18

looks better the name email phone

93:20

address city state ZIP code created at

93:22

an ID all right and I think we can take

93:25

credit I think we need to take out that

93:27

records thing for now

93:29

it's just annoying

93:31

okay so now we need to

93:33

put all of this stuff

93:35

inside this table so I'm just going to

93:40

grab all of this copy it and paste it

93:43

right in there

93:45

and this TR

93:47

I'm going to copy this it stands for

93:49

table row so

93:52

that will go here

93:55

have all that over and then let's close

93:58

the table row so we can get rid of that

94:01

one there

94:03

so for each record it will Loop through

94:06

here and create a new row a

94:09

table row with each of these things now

94:13

the actual columns we designate those

94:15

with TD tags and

94:18

closing TD tags so again I mentioned we

94:22

want a first name and last name in the

94:25

same column

94:26

right I think that makes sense

94:28

and then for the rest of these we just

94:30

give them a TD so I'm going to copy and

94:33

paste

94:35

like that very quick and then same thing

94:38

here we want to close our TD tag oh let

94:41

me just sort of

94:43

paste this in

94:46

that's pretty fast I got skills

94:49

okay so let's go ahead and save this and

94:51

refresh and see if that all matches up

94:54

and okay looks like it does name John

94:56

Elder notice how we put both the first

94:58

name and the last name in the name

95:00

category you could have a you could have

95:03

a column for a first and a column for

95:05

last name if you want I don't know I

95:07

think this looks better

95:09

uh name email phone address I'm just

95:12

checking to make sure everything lines

95:13

up looks like it does okay so we're good

95:16

to go so now we want to modify this

95:18

because this does not look great right

95:20

so uh bootstrap has all kinds of cool

95:22

things you could do so just come through

95:24

here and look and see what you like now

95:26

striped Rose I like that that looks

95:28

pretty good so to add that we just add

95:30

this table striped class to our our main

95:34

table class so if we come back up here

95:36

and go to the top here's our main table

95:38

class we just inside these quotes add

95:40

table striped save this and back over

95:43

here hit reload and okay now they're

95:46

striped we only have two records so

95:47

there's only two stripes but you can

95:48

imagine it looks better uh what else we

95:51

got uh let's come through here

95:57

different types of stripe uh hoverable

96:00

so when when you go over it's it hovers

96:03

I think that's cool let's do it up so we

96:05

just copy this table Dash hover

96:07

and again we just paste it into the same

96:10

spot we give a little

96:12

space there and paste it in space and

96:14

paste all right so let's come back over

96:17

here hit reload now when we hover

96:21

it changes color very cool what else we

96:24

got here

96:25

active tables no we don't need that

96:28

uh what else table borders I like

96:31

borders

96:33

because otherwise

96:35

it looks incomplete to me so let's add a

96:37

border again

96:40

space and paste I'm going to run that

96:42

into the ground catchphrase

96:45

all right so now we've got that okay

96:47

that looks better

96:49

what else

96:51

we could make it into a small table

96:54

right giving it a table SM command I

96:57

don't know that I want to do that but

96:59

let's take a look space and paste

97:04

I'm easily amused if you didn't figure

97:06

that out so if you hit reload boom it

97:08

just scrunched together I do not like

97:10

how that looks so we're gonna take that

97:12

out

97:14

save that come back over here hit reload

97:18

much better I like space space is good

97:20

uh you can have dividers man

97:24

vertical alignment

97:25

whatever you like play around with all

97:27

this stuff

97:28

we can change the color of the head too

97:31

dark I like that to do that we give a we

97:34

give our table head tag this class

97:38

so let's copy this

97:41

and find our table head tag

97:44

and there it is so space and paste

97:48

save it and back over here

97:52

reload and yeah I like that that looks

97:55

good

97:55

and now we're moving right along so yeah

97:57

that was pretty easy so now we need a

98:01

few different things right we need the

98:02

ability to add a record on the web page

98:05

we also need to and the ability to click

98:08

on one of these and go somewhere and

98:10

view the record on its own we can do

98:12

that we also want to edit those records

98:15

probably when we click on them and view

98:17

them as their own on their own so we

98:19

need to do all of those things so that

98:21

is up next

98:28

so yeah let's make this ID clickable so

98:31

when we click on it you could do the

98:32

same thing for the first name if you

98:33

want have it clickable and then let's go

98:36

to a separate web page where we can view

98:37

just that record right so let's head

98:40

back over to our code hit our urls.pi

98:43

file we need a URL for that so I'm just

98:45

going to copy this last guy here and

98:48

let's call This Record because we want

98:50

to look at specific records and now we

98:52

want to pass something we want to pass

98:53

an integer as a primary key right and

98:58

you'll see what this is in just a second

99:00

we want to point this to views dot let's

99:02

call this

99:04

I don't know customer underscore record

99:07

and let's point this to record

99:12

go ahead and save that now head back

99:14

over to reviews.pi and let's come down

99:16

here and let's define customer

99:19

underscore record

99:21

we want to pass in the request

99:23

we also want to pass in that primary key

99:27

what primary key well if we go back to

99:30

our urls.pi file

99:31

that's this thing right here right so

99:34

this will essentially look like uh you

99:36

know localhost

99:39

colon 8000 forward slash record forward

99:43

slash two right and the reason why is

99:46

because that two

99:48

will be the primary key it will pass

99:50

into the view it'll come in here then

99:53

we'll take that to or whatever and we'll

99:55

pump it into the database and say hey

99:57

return record number two right so we

100:00

know

100:01

for instance that Mary Smith is two and

100:05

then Django will return Mary Smith's

100:07

record so that's just a very quick and

100:09

easy and normal way to look up specific

100:11

records from a web page so let's head

100:13

back over here

100:14

and let's build this guy out so we

100:17

probably don't want everybody in the

100:18

world viewing these records you we

100:20

probably only want you to be able to see

100:22

them if you're logged in so we can check

100:23

right here if you're logged in or not so

100:25

we could go if request

100:28

dot user

100:30

dot is underscore authenticated

100:36

then let's look up that record so look

100:39

up record

100:41

how do we do that well I'm going to

100:43

create a variable called customer

100:44

underscore record

100:46

and we're going to set that equal to

100:47

record

100:48

dot objects

100:53

dot get and we want the ID to equal PK

100:57

which is that number they got passed in

100:59

with our request right and the ID of

101:02

course is the ID from our migration

101:06

this guy right it's our primary key

101:09

right they're unique everybody's record

101:11

has a unique primary key so you'll

101:14

notice this lookup thing here if we come

101:17

back here

101:18

to our home page we we looked up

101:22

record.objects.all to get all of the

101:24

objects to get a single object we call

101:27

record.objects.get and then pass in the

101:30

ID that we want to get and then it will

101:32

take that record and assign it to this

101:34

variable that we can then pass on to the

101:36

web page and view on the web page in the

101:38

same manner we've done other things like

101:40

that like here and here all right so let

101:43

me grab this guy and just copy it and

101:46

paste it underneath here instead of

101:48

going to register.html we want to

101:50

probably go to what record

101:53

that HTML and instead of passing form we

101:56

want to pass the customer record

101:59

so boom

102:02

and boom

102:04

okay

102:05

now

102:07

that's if the user is authenticated if

102:09

they're not then let's create a little

102:11

message and I'm just going to come up

102:13

here to one of these other messages

102:16

and copy them paste them in

102:22

make sure the tab correct they're tabbed

102:24

correctly and let's throw up a little

102:25

message that says you

102:28

must be logged in to view that page

102:35

and then we'll redirect them to the home

102:37

page

102:38

so okay let's go ahead and save this now

102:40

we need a record.html page so I'm going

102:43

to copy this remember Django is always a

102:45

three-step process when you're creating

102:46

something you need a URL you need a view

102:48

and you need the page so this is the

102:50

view we already did the URL now we just

102:52

need the page head over to templates

102:54

right click new file file save as and we

102:57

want to save this as record.html or

102:59

record.html

103:00

and then let's grab our

103:06

maybe our register page I just want to

103:08

copy these things here

103:11

very quickly our block tags

103:14

foreign

103:17

let's just say uh

103:20

customer record

103:23

for now we'll change this in a second I

103:24

just want to make sure this works for

103:26

now

103:27

and there we go so let's give this a try

103:29

so let's head back over here and let's

103:31

go to record slash one and what we do it

103:35

says customer record good now if we're

103:38

logged out and we go to

103:41

record slash one

103:43

it says You must be logged into the Via

103:45

this page and it sends us back to the

103:47

home page all right

103:49

so let's log in here

103:56

now we want to make these clickable with

103:58

a link so how do we do that so let's

104:00

head back over here to our home

104:04

and I've noticed that the login screen

104:06

was different so let's go back to our

104:10

register page and let's grab this div we

104:13

took it off a bit ago so this entire

104:16

table would fit but down here in the

104:19

login we probably want to put it back so

104:21

let's save this now let's just test that

104:23

real quick log out okay now it's

104:26

centered again

104:29

but likewise this one is allowed to

104:31

stretch out so okay that's what we want

104:33

so now let's add these links right here

104:35

so head back over to the home page

104:37

and for the ID you could do it like I

104:40

said on the first name last name but I'm

104:42

going to do it just for the ID

104:44

the process is the same let's go H or f

104:47

equals

104:50

like that and then we want to close our

104:52

H our a tag and then here we create a

104:55

Django link URL tag and we want to pass

104:59

this to a record

105:01

but we also want to pass in the record

105:03

dot ID

105:06

so if we save this head back over here

105:08

hit reload now we have these links if

105:11

you hover though so look down here in

105:14

the corner down in the bottom left hand

105:15

corner it says record four slash one if

105:19

I go to this one it says record forward

105:21

slash two that's what

105:23

this thing here does it puts the ID

105:27

which we know is this guy right here

105:30

into this link so okay let's go try that

105:34

let me reload it again and let's click

105:36

on this and boom customer record all

105:39

right now it goes to record slash one

105:43

and record slash two but there's nothing

105:46

showing up on those pages right now so

105:48

we need to change that so back to our

105:51

views.pi file and

105:53

let's see here is where we're passing in

105:57

the customer record we have the customer

105:59

record we can access it on the page so

106:02

let's copy this and let's head back over

106:04

to our record.html and here I can just

106:08

pop in the customer record

106:11

so if I save this

106:13

head back over here hit reload we get

106:15

Mary Smith

106:16

come back again click one we get John

106:18

Elder now again it's the same deal it's

106:21

it's putting out the default thing we

106:24

can break it down into into everything

106:26

in the record if we want so let's go

106:29

ahead and do that so I'm going to go

106:30

back over to our home page and we're

106:33

going to do some copying and pasting

106:34

here

106:35

as we want all of this stuff

106:39

so

106:41

let's go back to our records page and

106:43

instead of that let's pop this in

106:46

um

106:49

we need to we could take out all of

106:50

these things

106:54

very quickly here

106:58

not as fast as deleting as I am as

107:00

copying and pasting

107:06

[Music]

107:09

very exciting work here

107:13

okay so again we probably want little

107:16

spaces here because this is all going to

107:17

be on one line until we fix it we don't

107:19

want a URL here so we'll take out this

107:21

link

107:23

as well okay so let's just save this and

107:26

see what we got here

107:28

hit reload oh

107:30

everything is gone wonky

107:33

oh this should be customer underscore

107:36

record obviously

107:42

oh let me just paste paste paste paste

107:46

paste and paste okay save this head back

107:50

over here now that should work and boom

107:52

we get all of John Elder's stuff

107:54

scrunched onto the screen so all right

107:56

that's not great we need to want to

107:57

format this a little bit so let me just

108:00

move this over make it look nicer and we

108:03

can start out by adding some line breaks

108:08

so let me copy this

108:14

there we go save this head back over

108:17

here

108:18

all right that's looking a little bit

108:20

better not a whole lot better but uh

108:22

let's see we're missing a first name and

108:25

last name here

108:26

oh I forgot to

108:29

add

108:30

this this is what happens when you copy

108:32

and paste

108:34

all right let me there we go that's

108:36

easier to read so now

108:39

all right so

108:46

okay that's not great let's make this

108:50

look nicer so let's head back over to

108:52

bootstrap we always go to bootstrap when

108:53

we want to make things look nicer and

108:55

head down to components and let's grab a

108:57

card so I'm just going to scroll through

108:59

here until something catches my eye

109:03

and uh oh this looks good let's grab

109:06

this so I'm going to copy this head back

109:08

over here

109:09

and

109:11

let's get rid of customer records and

109:14

let's paste in this card so if we save

109:16

this head back over here and just look

109:18

and see what we have we got this nice

109:19

looking card that looks pretty good

109:21

where it says featured let's put the

109:23

name all right

109:26

I think that'll look professional so I

109:28

can just get rid of this BR and copy

109:31

this first and last name and let's just

109:34

boom pop them right in there so

109:37

let's save this head back over here see

109:40

how that looks

109:43

that says John Alder there very cool

109:45

let's get rid of this button here we

109:47

don't need that

109:49

so that's this guy right here

109:53

get rid of that save it

109:56

reload it all right that looks better

109:59

and then maybe right here where it's a

110:01

special title treatment that's where

110:03

we'll put everything else and we'll get

110:05

rid of this one here so

110:07

ah that would be this

110:11

otherwise it's going to be card title H5

110:14

for everything in our list here so maybe

110:17

we want that maybe we don't

110:19

for now

110:22

let me get rid of all these br's

110:31

there we go and we could just copy all

110:34

of this stuff Ctrl C to copy or right

110:37

click and copy and right here

110:41

I'm just gonna paste all these things in

110:43

so I'm a little I'm a little torn we

110:47

could

110:48

do like this

110:51

for each one of these

110:56

so

110:59

like that

111:01

you know on and on let's save this and

111:04

see what this looks like

111:10

all right so if the size of the text is

111:12

what you want I don't really like that

111:14

size of that text so let's change this

111:15

out instead of using the chord title H1

111:19

let's use this p uh class card text I

111:23

think that probably will be better so

111:25

let me just copy this and here we'll

111:27

just do it like this we'll get rid of

111:30

this

111:32

and this

111:34

and all of these things

111:40

all right

111:44

and instead of H5 tag this will be a

111:47

closing P tag now

111:49

actually we do now I'll need all of

111:52

those line breaks that we deleted

111:54

so I don't know play around with this

111:56

make it look however you want I'm bad at

111:59

design stuff

112:01

uh but uh that should work let's take a

112:04

look at this and

112:06

and we don't need the John Elder because

112:08

it's already there so see we'll take

112:11

that out

112:14

there we go

112:18

so maybe that's good enough maybe you

112:21

want to put the email phone City like

112:23

the words in front of them maybe

112:25

something like that so let's go strong

112:28

strong

112:31

let me copy this for each of these guys

112:38

and inside of here maybe we type in like

112:41

email

112:43

and then

112:46

phone

112:48

and this is becoming unruly address

112:52

though you probably want to put some

112:54

spaces around here so City

112:59

all right

113:00

state

113:04

zip code

113:10

created at

113:12

and finally

113:14

ID

113:16

something like that again this is

113:18

beginning to be ridiculously hard to

113:20

read so I'm going to put some spaces

113:22

after the br's

113:24

so at least it's a little bit easier to

113:27

designate what's what here so all right

113:30

go ahead and save this or you could just

113:32

kinda

113:33

see

113:34

highlight all of this stuff and tab it

113:37

over a few times

113:39

it makes it a little easier to read

113:41

whatever good enough let's head back

113:44

over to the page and hit reload and ah

113:46

there we go like that I don't know it

113:48

still seems a little scrunched together

113:50

to me so instead maybe we do a P tag for

113:54

each thing and instead of a br let's get

113:57

rid of those again

113:59

we do something like this

114:04

let me save this and reload it see

114:08

yeah that puts some space in between

114:09

each item maybe that's what you like

114:12

whatever you like

114:14

I think maybe I'll do that real quick

114:15

here

114:19

just add

114:21

peas

114:22

each of these guys

114:25

and then

114:30

like that

114:34

there we go get rid of this one

114:41

and this is not very exciting

114:45

television is it

114:47

or YouTube division

114:50

okay so save this

114:53

we could Tinker with this all day and

114:55

that looks good whatever and here John

114:58

Elder maybe you want to make that bold I

115:00

don't know let's go strong

115:04

strong I don't know we're just playing

115:08

around at this point

115:10

whatever whatever you like uh it's

115:13

totally up to you like that and uh yeah

115:17

looking good so we might want a back

115:19

button down here below

115:21

so let's go test save this

115:24

make sure we're in the right spot yep

115:26

there it is

115:27

so we definitely want line breaker 2

115:31

there and we can create a little

115:34

button here we can go href equals

115:39

and this is going to be a Django URL tag

115:42

you want to send it back to what the

115:45

home page probably

115:48

right

115:50

and then here we can have it say back

115:56

and then inside of here we can make it a

115:57

button by giving it a class equals BTN

116:00

space BTN Dash let's say secondary

116:05

something like that that will make a

116:07

gray button so if we hit reload we've

116:10

got this back button now will we go to

116:13

Mary she's got a back button

116:15

very cool so okay step one put the thing

116:18

on the screen step two maybe we want to

116:21

delete so we want to delete button right

116:23

so let's come back over here let's grab

116:26

this guy

116:28

and right next to him let's put a

116:32

let's say delete button instead of

116:35

button secondary let's put button danger

116:37

that will make it red and scary

116:39

so there we go now it says delete we

116:42

click delete it goes back it doesn't

116:43

actually delete yet we're gonna have to

116:45

build that functionality in and um let's

116:48

go ahead and do that now so all right

116:55

what are we doing here we're doing a

116:57

thing in Django things in Django are

116:59

always three-step processes you need a

117:00

URL you need a view and you need the

117:02

thing in this case we don't need the

117:04

thing we're not sending them to a delete

117:06

page we're just doing an action so

117:08

actually we need two things this time

117:10

but we can start to do that head over to

117:13

urls.pi file and let's copy this guy and

117:16

paste it in and let's Create A New Path

117:18

a new URL and instead of calling This

117:21

Record I'm going to call it delete

117:23

underscore record again we still want to

117:25

pass this primary key because we need to

117:27

know which record to delete right so

117:30

that makes sense and here instead of

117:32

customer record let's call delete record

117:35

and for the name again let's call delete

117:38

underscore record oh okay that looks

117:41

good

117:43

save that head back over to reviews.pi

117:45

file and let's create a new view

117:49

so Define delete underscore customer

117:53

pass in our request we also want to pass

117:55

in that primary key so we know which

117:57

record to delete very important and

117:59

deleting records is pretty easy sort of

118:00

like logging out there's not much to it

118:02

so I'm going to create a variable called

118:03

delete it all right and this is going to

118:05

be a record dot objects

118:08

dot get just like when we looked it up

118:11

earlier we still just want to pass in

118:13

the ID of primary key right that will

118:16

get the record that we want to delete

118:18

now we just delete it so we call delete

118:20

underscore it dot delete

118:23

and that's it so again just like earlier

118:27

when we're logging in and logging out we

118:29

probably want to

118:31

flash up a little message or something

118:33

right

118:34

so

118:35

let's say

118:38

record

118:40

deleted

118:42

successfully dot dot dot and we probably

118:45

want to send them back to the home page

118:46

now anybody can do this so we probably

118:50

want to say only do this if the person

118:53

is logged in right so let's grab all of

118:56

this

118:59

else let's say

119:06

again

119:07

you must be logged in to do that

119:13

thing to do that I don't know whatever

119:16

and pass them to the home page all right

119:19

let's go ahead and save this and see if

119:21

that worked I'd be very very sad to see

119:23

Mary Smith go but

119:26

in the name of science uh oh we've got a

119:28

we've got an error

119:30

at our terminal uh oh delete record I

119:34

did not save ah we called this delete

119:36

customer

119:37

what did we call in our urls.pi delete

119:39

record so that's the problem

119:43

Elite record there we go save this now

119:46

if we head back over here and hit reload

119:48

there we go so like I said Mary Smith's

119:50

gotta go click Mary Smith click delete

119:53

and that did not work because we didn't

119:56

update our button here so all right

119:58

let's head back over here to our

120:00

record.html come down here to our delete

120:02

button and this needs to go to I've

120:06

already forgotten again what we've

120:07

called it delete record so the name of

120:09

this is delete record

120:12

copy this add back over here and instead

120:15

of pointing this to the home page we

120:17

need to point it to delete record and

120:19

again we need to pass our customer

120:22

underscore record

120:24

dot ID all right so go ahead and save

120:26

this Mary is just sticking around didn't

120:29

she now when we hover over here you see

120:30

down at the bottom it says delete

120:31

underscore record forward slash two so

120:33

let's start over let's click here boom

120:36

two Mary Smith

120:38

nice knowing you record deleted it

120:40

successfully oh it says records deleted

120:43

let's change that

120:45

so

120:46

record there we go all right not bad and

120:51

that was pretty easy so all right so

120:52

moving right along we can see all of our

120:54

records on the home page we can click on

120:56

each individual one see them

120:57

individually that looks decent and we

121:00

can delete them or go back now let's add

121:04

records

121:10

so let's head over urls.pi file

121:13

and I'm gonna grab

121:16

one of these and let's call add

121:19

underscore record

121:21

and this is going to be views Dot

121:24

add underscore record

121:28

and here the name we'll call it add

121:30

underscore record

121:31

so that looks good

121:33

I'm gonna go ahead and copy this and

121:35

let's head back to our views.pi file and

121:37

let's create a new view so let's define

121:40

add record we pass in our request as

121:43

always

121:45

and let's see let's come up here and

121:49

grab one of these guys here

121:52

come down here paste it in so again

121:55

we're going to point this to add

121:56

underscore record dot HTML we haven't

121:59

created that yet so let's do that we

122:01

don't need to pass anything in just yet

122:03

we might later we'll see go ahead and

122:05

save this now head over to

122:08

templates right click new file file save

122:11

as and we want to save this as

122:13

add underscore record dot HTML

122:17

and again let's head over to our record

122:19

page

122:21

and grab

122:23

these basic things and let's say H1 add

122:27

record

122:30

and head back over here again grab the

122:33

end block

122:35

paste that in okay that looks good now

122:38

let's add a link to this in the nav bar

122:39

so let's head over to our template slash

122:42

navbar

122:44

and we probably only want to see this if

122:47

a user is logged in right so that's

122:48

going to be in our is authenticated

122:50

block right

122:53

so let's say right here let's give this

122:57

a link to add record

122:59

and we want to point this to add

123:01

underscore record

123:03

save it and back over here hit reload

123:06

now we have this add record link well I

123:09

click it it goes to this add record page

123:11

and uh yeah looking good so all right

123:14

let's build out this add record page

123:15

it's getting exciting so let's head back

123:17

over here I'm gonna go to my home page

123:19

and come down here

123:22

and grab this centering thing that we've

123:25

been playing with in the past

123:29

and let's add a little line break and

123:32

let's also go back here and grab our

123:34

form stuff here

123:36

so grab this

123:40

and what else we need this closing stuff

123:45

and a button so we'll just copy this as

123:48

we go along this gets easier because we

123:49

can just reuse code that we've already

123:52

played with in the past so here let's

123:54

have it say add record and instead of

123:57

pointing it to home we want to point it

123:58

to add underscore record

124:01

okay that looks good and let's just

124:05

create a form for this so let's go form

124:07

dot as underscore p and like I said

124:10

we're going to create a Django form for

124:11

this

124:12

so all right that looks good so now

124:16

let's head back over here and let's go

124:18

to our forms dot Pi file and let's build

124:20

out this form so here's our sign up form

124:22

we could just come down here below it

124:25

and create

124:28

add record form so let's create a class

124:31

and I'm going to call it add record

124:34

form and this is going to inherit forms

124:37

dot model form

124:40

like that now we don't have to import

124:42

model form because we've already

124:44

imported forms so up here we from Django

124:47

import forms that will allow us to use

124:50

the model form and a model form is just

124:52

what it sounds like it takes a form and

124:54

adds it to the model our model is the

124:56

record model so we need to import that

124:58

so let's go from dot models

125:01

we want to import record

125:03

and now we can use that on this page so

125:06

let's come down here and build this guy

125:07

out so we want a first underscore name

125:11

we want our last underscore name

125:14

we want well basically all the things

125:18

from our model dot Pi file so first name

125:21

last name created at we don't need that

125:24

because Django does that for us but we

125:28

need email phone and address so

125:34

let's go email

125:36

phone and address what else we got

125:42

city state ZIP code

125:45

so City

125:49

State and zip code

125:52

we also don't need the ID Django will

125:55

create that for us so up here let's

125:57

create one let's go forms dot car field

125:59

it's almost always a car field right

126:01

and we probably want to set required

126:05

equal to true for all of these because

126:07

we want

126:08

info for every one of these we don't

126:10

want people to be allowed to leave

126:12

anything blank right so okay so like

126:15

earlier we need to set a widget and this

126:18

is going to be forms.widgets

126:21

dot text input

126:25

and again we need our adders

126:28

curly brackets and here let's give this

126:31

a place holder text

126:35

of first name

126:39

and we also want to give this a class

126:44

of form Dash control for the

126:47

bootstrapifying make it look nice with

126:49

bootstrap

126:50

and then outside of here let's also

126:52

create a label and set it equal to

126:54

nothing now again this is a lowercase L

126:56

both of these are I know they look like

126:59

they're not but they are

127:01

and that looks good so I'm just gonna

127:03

copy all of this stuff

127:06

and let's paste it in for each one of

127:10

these

127:14

okay but this is going to be last name

127:20

this is gonna be email

127:23

this is gonna be I think phone

127:27

let's make sure yep that looks good

127:31

address city state ZIP code

127:36

so address

127:40

City

127:44

state

127:47

and zip code

127:50

okay that looks good so I know this is

127:53

kind of hard to read again you can look

127:54

at it on my GitHub page if you need to

127:57

now we also need to set our class of

127:59

meta and designate what model we want to

128:02

use so model equals is going to be our

128:05

record model we also can either

128:07

designate the fields or we could just

128:09

say exclude and set it equal to our user

128:14

and a comma and that will just add all

128:17

the fields so that's an easier way to do

128:19

it sometimes you can get away with doing

128:20

it that way and in this case we can so

128:23

okay let's go ahead and save this so we

128:24

have this add record form let's now

128:26

import that to our views.pi file so up

128:28

here at the top we want from forms

128:31

import signup form and add record form

128:33

so now we can use this in our view so

128:36

let's do that down here to our add

128:38

record View and let's designate a form

128:41

and this is going to be our add record

128:43

form and let's go request dot post or

128:47

none so this will allow us to say hey

128:50

are they posting the form are they

128:51

adding a record if not just go to the

128:54

web page so that's a second way to do

128:56

that we did it a little bit differently

128:58

earlier but I like to show you different

128:59

ways to do the same things in case

129:01

something is better suited to whatever

129:03

you happen to be working on so let's go

129:05

if request

129:08

dot user dot is underscore authenticated

129:12

if they're logged in then let's allow

129:14

them to post so let's say hey if request

129:17

dot method

129:20

equals

129:24

host

129:26

then again from earlier we need we know

129:30

we need to say hey is this thing valid

129:31

so let's go if form dot is underscore

129:34

valid

129:37

then what well let's add underscore

129:39

record equals form dot save

129:44

and again unless messages dot success

129:48

SNR request

129:50

and let's say I don't know record added

129:53

that whatever and then let's return

129:56

redirect

129:59

to the homepage

130:01

okay

130:03

otherwise if they're not posting

130:07

then we just want to well

130:10

do this guy

130:11

make sure this lines up with this if

130:14

statement for the Post right

130:18

but we want to pass in the form so form

130:24

colon form because we want that form to

130:27

show up on the page if they're not

130:28

filling out the form it means they want

130:30

to fill out the form so we need to pass

130:31

the form onto the page right

130:34

all right else so if they're

130:37

authenticated do all this stuff

130:39

otherwise they're not authenticated so

130:41

we need to send them a little message

130:44

uh let's just copy this

130:49

right and let's just say what

130:53

you must be logged in whatever

130:59

okay so let's go ahead and save this and

131:01

that should do it let's try this out so

131:03

let's go add record and we've got this

131:05

nice form now I'm going to copy this

131:08

link and let's log out

131:11

now let's go to that page ah you must be

131:14

logged in that works so let's log us in

131:18

now we can add a record and let's bring

131:20

Mary Smith back man she was she was

131:23

something right Marriott mary.com Mary's

131:26

phone is 555

131:28

that's not six she lived at 10 Mary way

131:33

in Maryville

131:37

Illinois

131:40

with that zip code all right fingers

131:42

crossed add record boom record added

131:44

there she is

131:46

and now her ID is three because it's

131:48

incremental right the last one was two

131:50

we deleted that the next one will be

131:52

three that's how primary Keys work and

131:55

we're good to go so we are moving right

131:56

along we can add records

131:59

right

132:00

we can log out we can log in

132:05

we can register now all we need is the

132:08

ability to update our record

132:15

so let's come through here head back

132:17

over to our record page

132:19

and where did that go right there and

132:22

let's grab this now let's grab this link

132:24

here

132:28

and let's say what

132:31

update record

132:35

and let's pass this to update underscore

132:37

record

132:39

so now we need to create this guy

132:41

all right so save this head over to our

132:43

urls.pi file and I'm going to copy this

132:46

delete guy because you guessed it we're

132:48

going to have to pass the primary key

132:49

again because we need to know which

132:51

record to update right so here instead

132:54

of delete record this will be update

132:55

record and this will point to our update

133:00

record View

133:02

and let's call this guy

133:04

update record okay so save that head

133:07

over to reviews.pi file

133:10

and let's define update underscore

133:13

record

133:14

we want to pass in our request as always

133:16

and also that primary key because we

133:18

need to like I said look up which record

133:20

to update and we only want to allow this

133:23

if somebody's logged in as always so I'm

133:25

just going to copy this guy

133:29

and if the request.user.is authenticated

133:31

what do we want to do well let's grab

133:33

our current record

133:34

right

133:36

and this is just going to be the same

133:38

thing we've done before

133:43

let's just grab this

133:47

so this is going to be

133:49

record.objects.get

133:51

the ID of whatever that primary key is

133:54

assign that record to this current

133:56

record and now we can play with it so we

133:59

can use this ad record form so I'm going

134:02

to just grab this whole thing

134:04

copy it and paste it

134:06

now

134:08

what we want is when somebody goes to

134:10

this page and this form pops up we want

134:13

it to be already what's the word

134:15

propagated with whatever the record is

134:18

and we can do that by just passing right

134:21

here where it says or none

134:23

we could just give this an instance

134:25

of the current underscore record

134:29

and we've defined what that current

134:30

underscore record is right here it's the

134:33

record with the primary key that we

134:34

passed into the page right we've grabbed

134:36

that record we can pass it back to the

134:38

page in an instance of it just like that

134:41

so very very cool and uh actually pretty

134:44

simple so now we've done hey are they

134:48

posting or are they doing nothing if

134:50

they're doing nothing it means they want

134:51

to post they're going to change

134:53

something and then resubmit it otherwise

134:56

they're going to post so if they have

134:57

posted right so let's go if

135:02

form

135:03

dot is underscore valid we've seen this

135:06

before

135:07

we just want to form dot save the guy

135:09

right and then let's throw up a little

135:12

message

135:13

because we're marrying and helpful

135:16

people right and let's say

135:20

record

135:22

has been updated

135:24

and we just probably want to redirect to

135:27

the home page

135:28

all right otherwise

135:30

let's just show them to the page so

135:33

let's come down here and paste this guy

135:35

in and instead of add record

135:38

this is going to be update record

135:41

and we still definitely want to pass in

135:43

that form right which is this guy else

135:48

so if they're authenticated do all this

135:51

otherwise let's throw up a message let's

135:55

just copy this guy right here

135:58

you must be logged in redirect them back

136:00

to the home page okay so now we need

136:03

this updaterecord.html page it's easy to

136:05

forget about that guy but let's go ahead

136:08

and save this and head over to our

136:09

templates right click new file file save

136:12

as update underscore record.html

136:15

and again let's just kind of grab some

136:17

stuff here actually let's grab all of

136:19

this stuff we're probably gonna need it

136:23

so ah we don't even need this let's get

136:26

rid of this action let's streamline this

136:28

stuff csrf token form as p

136:31

uh add record let's change the button to

136:33

say update record yeah pretty much

136:36

everything is going to be the same

136:38

uh we have this guy here we never really

136:40

close that div tag which means we

136:43

probably didn't over here either in our

136:45

ad record

136:46

that's just bad form

136:49

still works still valid it's just not

136:51

good form so okay uh update record that

136:54

looks good so

136:56

now if we head back over to the web page

136:59

we need to fix our button here so this

137:03

is on the regular record page so let's

137:05

go to our record at HTML and down here

137:09

we created this update record but we

137:11

need to pass the customer underscore

137:13

record

137:14

dot ID so we know which one to update

137:17

right obviously let's go come back over

137:20

here create some reloads all right so

137:22

Mary Smith

137:24

here she is we want to update her boom

137:26

here is the form it's already filled out

137:29

with Mary Smith's stuff which is awesome

137:31

notice there's no field for ID we don't

137:34

want to be able to change the ID that's

137:35

the primary key you can't change that

137:37

and you also don't want to be able to

137:38

change the created at field because

137:42

that's no good either you can add an

137:44

updated at field if you wanted to I'll

137:45

leave that to you same principles as the

137:48

created at field you just you know

137:50

Tinker around and add it here but let's

137:52

change Mary to Mary to update record

137:53

record has been updated it says Mary to

137:56

Smith and that seems to have worked

137:59

if you come back here we want to change

138:00

it back

138:01

get rid of that update record boom

138:04

record has been updated and we are good

138:06

to go I think that's it I think we are

138:09

done right has everything you would want

138:11

to do we can register we can log in we

138:14

can log out we can see all the records

138:16

we can add a new record

138:19

we can

138:22

maybe we want to put a button here that

138:23

says back

138:24

I don't know if we click we can click on

138:26

an individual record to view it we can

138:28

delete it we can update it we can go

138:30

back

138:32

yeah let's do that add record page very

138:35

quickly

138:36

uh down here let's just create another

138:39

button

138:42

and instead of saying add record let's

138:44

have it say back no actually let's go to

138:48

our record page and let's grab this back

138:52

guy because this is an actual link which

138:54

is easier

138:56

and we're just going to copy and paste

138:58

all right save that now let me come back

139:01

here and hit reload it says back yeah

139:03

that's nice all right and we're good to

139:06

go we've got the link here to click on

139:08

the ID maybe you want Mary Smith to be

139:11

clickable as well or instead we could do

139:14

that go to our home page and

139:18

come up here and let's just grab this

139:21

link and like I said we could easily

139:24

just as easily add it to our first name

139:26

and then close it right here

139:29

save this and back over here it reload

139:32

now the names are clickable instead of

139:34

the ID when we click on John Elder it

139:36

goes to John Elder

139:38

we could you know just as easily put

139:41

another column here that says click here

139:43

to update if you wanted to update from

139:46

this page we could do that as well it's

139:49

trivia I'll leave that to you I'm going

139:51

to take this out because I think that's

139:53

kind of ugly

139:54

I'm just gonna hit undo a couple of

139:56

times here save this head back over here

139:59

hit reload and we are good to go now one

140:01

last thing let's push all this final

140:03

code to GitHub so you have the updated

140:04

code

140:10

so to do that let's go get add period so

140:13

get commit Dash am and let's say final

140:17

project

140:20

whatever and then get push to push it up

140:24

to GitHub

140:26

let me run our server again just so that

140:28

it's running in the background now if we

140:30

come back over here go to github.com

140:31

forward slash flatplanet

140:34

and let's just do it like that

140:37

click on repositories

140:40

and then Django CRM

140:43

the complete final code is here that's

140:46

github.com forward slash flatplanet

140:48

forward slash Django Dash CRM there you

140:51

can find the totally completed code if

140:53

you like this

140:55

head over to codemy.com I have got like

140:57

over a dozen other Django courses if

141:00

you're into Django stuff basic Django

141:02

create a dental website Django to-do

141:04

list app Django authentication a whole

141:06

course just on authentication but we

141:08

pretty much covered everything here well

141:09

no we didn't actually there's more stuff

141:10

in there that's interesting stock market

141:12

app flash card app push your code to a

141:15

Roku app a weather app cryptocurrency

141:19

that's kind of outdated build an API

141:21

here's a couple of chat GPT courses this

141:23

one we created a code bot that chat GPT

141:26

will write code for you and give it to

141:27

you it's really cool this one is just

141:29

the basic chat bot so if you're

141:31

interested in Django check all those out

141:32

like I said you can always sign up for

141:35

membership

141:36

by clicking on lifetime membership which

141:38

is usually 249 dollars if you come over

141:41

here and type in YouTube 50 you get half

141:45

off so you get all of my courses over 50

141:47

courses and all my future courses at no

141:50

extra charge for a one-time fee of 125

141:52

which is pretty fantastic or you could

141:55

sign up for monthly for 12 bucks a month

141:57

you could get individual courses for 49

141:59

each or you can get yearly membership

142:01

for 99 bucks but honestly if you're

142:03

going to get yearly for 99 you might as

142:04

well sign up for a toll for just 25

142:08

bucks more or whatever 26 bucks more

142:10

that gets you all my future courses I've

142:12

got an aggressive course release

142:14

schedule this year 2023-24 so I'm trying

142:17

to release at least one if not two new

142:20

courses every month and so far we've

142:22

been able to do that and uh should be

142:23

good so all right I think we're gonna

142:25

call this guy done

142:27

pretty simple app but all kinds of cool

142:30

functionality in here and this is basic

142:32

crud applications create read update and

142:34

Destroy so we can create a record

142:37

right

142:38

we can read a record

142:41

yeah we can update it record yeah

142:45

and we can delete a record crud create

142:48

read update destroy if you're interested

142:50

in all things web development everything

142:53

on the internet is a crud application

142:55

create read update and destroy a

142:57

Facebook post is nothing more than crud

142:59

you create a Facebook post you read a

143:01

Facebook post sometimes you update a

143:03

Facebook Facebook post or sometimes you

143:06

delete a Facebook post everything

143:07

Twitter you can actually update a

143:09

Twitter tweet can you yeah

143:11

Instagram everything is just crud and

143:14

this is how you do crud and Django

143:15

pretty simple pretty straightforward and

143:17

very fun so that's all for this video if

143:19

you liked it be sure to smash like

143:20

button below subscribe to the channel

143:21

give me a thumbs up for the YouTube

143:22

algorithm and check out codemy.com or

143:24

you can use coupon code you do 50 to get

143:26

50 off membership so that's access to

143:28

all my courses over 50 courses thousands

143:30

of videos and the PDFs of all my

143:32

best-selling coding books doing over 150

143:34

000 students learning to code just like

143:35

you my name is John Elder from

143:37

codemy.com and I'll see you in the next

143:38

video

UNLOCK MORE

Sign up free to access premium features

INTERACTIVE VIEWER

Watch the video with synced subtitles, adjustable overlay, and full playback control.

SIGN UP FREE TO UNLOCK

AI SUMMARY

Get an instant AI-generated summary of the video content, key points, and takeaways.

SIGN UP FREE TO UNLOCK

TRANSLATE

Translate the transcript to 100+ languages with one click. Download in any format.

SIGN UP FREE TO UNLOCK

MIND MAP

Visualize the transcript as an interactive mind map. Understand structure at a glance.

SIGN UP FREE TO UNLOCK

CHAT WITH TRANSCRIPT

Ask questions about the video content. Get answers powered by AI directly from the transcript.

SIGN UP FREE TO UNLOCK

GET MORE FROM YOUR TRANSCRIPTS

Sign up for free and unlock interactive viewer, AI summaries, translations, mind maps, and more. No credit card required.