1
00:00:00,560 --> 00:00:06,140
Hey, we're here with another video where we will store these data to the database.

2
00:00:06,290 --> 00:00:13,640
To do that, after the occupation line, we want to access the form class dot.

3
00:00:13,670 --> 00:00:19,880
Now, forms should be imported from DOT models.

4
00:00:20,090 --> 00:00:21,940
Import form.

5
00:00:21,950 --> 00:00:23,180
What is form?

6
00:00:23,180 --> 00:00:25,850
Form is in Models.py.

7
00:00:26,150 --> 00:00:28,010
This is a database model.

8
00:00:28,010 --> 00:00:30,830
So we created this yesterday.

9
00:00:30,950 --> 00:00:34,100
So that is the model which creates the database.

10
00:00:34,100 --> 00:00:37,200
Don't confuse this with the forms model.

11
00:00:37,220 --> 00:00:38,920
This is application form.

12
00:00:38,930 --> 00:00:40,370
This is just form.

13
00:00:40,370 --> 00:00:47,030
So we import that in views dot models, import form and then we access the objects.

14
00:00:47,030 --> 00:00:54,140
Property dot create first name is first name.

15
00:00:54,140 --> 00:00:56,630
So this gets a series of arguments.

16
00:00:57,140 --> 00:01:02,190
So this corresponds to the columns of the database table, right?

17
00:01:02,210 --> 00:01:05,459
So first name is the column of the database table.

18
00:01:05,489 --> 00:01:12,240
The value of this column should be equal to the value of this variable first name.

19
00:01:12,240 --> 00:01:12,750
Right?

20
00:01:12,750 --> 00:01:18,270
So let's do the same for last name, last name, comma.

21
00:01:18,300 --> 00:01:19,530
Go to the next line.

22
00:01:19,560 --> 00:01:20,460
Email.

23
00:01:20,700 --> 00:01:21,660
Email.

24
00:01:22,350 --> 00:01:23,220
Date.

25
00:01:23,340 --> 00:01:29,100
Date occupation is also occupation.

26
00:01:29,690 --> 00:01:34,670
So this line should be able to store the data in the database.

27
00:01:34,670 --> 00:01:36,050
So let's try it.

28
00:01:36,170 --> 00:01:38,720
Run the app if you haven't done so already.

29
00:01:38,720 --> 00:01:40,670
So let me quit it and run it again.

30
00:01:40,670 --> 00:01:46,160
Perhaps just so that we have a fresh execution even though it's not necessary.

31
00:01:46,670 --> 00:01:48,170
So let's go here.

32
00:01:48,350 --> 00:01:49,580
Reload.

33
00:01:49,970 --> 00:01:51,380
Fill in the data.

34
00:01:54,490 --> 00:01:56,940
Employees and let's see what happens.

35
00:01:56,950 --> 00:01:58,420
We've got an error.

36
00:01:58,420 --> 00:01:59,920
Oh, keywords email.

37
00:01:59,920 --> 00:02:02,230
Sorry, I have a typo here.

38
00:02:03,370 --> 00:02:12,370
Email I change that to email, save with ctrl or command s reload and.

39
00:02:14,810 --> 00:02:16,100
Again submit.

40
00:02:16,280 --> 00:02:18,710
So no errors this time.

41
00:02:19,520 --> 00:02:28,820
So now I want to open DB browser for SQLite and I want to go to.

42
00:02:30,250 --> 00:02:37,840
The database file in my app 17 Django form DB dot sqlite3.

43
00:02:38,530 --> 00:02:43,180
So I'm opening this DB dot sqlite3 file.

44
00:02:43,180 --> 00:02:43,440
Right.

45
00:02:43,480 --> 00:02:46,240
Which is in your project's root directory.

46
00:02:46,890 --> 00:02:51,630
I want to go to the job application form table.

47
00:02:51,630 --> 00:02:53,630
And there are the data.

48
00:02:53,640 --> 00:02:54,900
So there we go.

49
00:02:55,090 --> 00:02:55,470
Right.

50
00:02:55,470 --> 00:02:57,360
So that's working good.

51
00:02:57,780 --> 00:03:04,050
And next, let's display a message here to tell the user that the data was was submitted successfully.

52
00:03:04,080 --> 00:03:12,450
Let's go to PyCharm Views.py and you want to import from Django.

53
00:03:13,130 --> 00:03:18,340
Dot contrib import messages.

54
00:03:18,350 --> 00:03:27,320
So messages is a Django module which allows you to display messages dynamically on your web pages.

55
00:03:27,590 --> 00:03:32,300
So let's go here and delete that print function.

56
00:03:32,300 --> 00:03:36,560
We don't need it anymore and say messages.

57
00:03:36,560 --> 00:03:40,700
So the module we just imported dot success.

58
00:03:42,300 --> 00:03:45,840
This is a function that gets the request.

59
00:03:46,680 --> 00:03:48,810
The request is this here.

60
00:03:48,810 --> 00:03:49,440
Right?

61
00:03:49,470 --> 00:03:50,560
We are inside.

62
00:03:50,580 --> 00:03:57,480
Index request goes as the first argument, followed by the message you want to display, which could

63
00:03:57,480 --> 00:04:02,790
be something like form submitted successfully.

64
00:04:03,060 --> 00:04:05,490
So let's go back again.

65
00:04:05,850 --> 00:04:06,960
Reload.

66
00:04:07,200 --> 00:04:08,400
Fill in the data.

67
00:04:10,860 --> 00:04:11,820
Submit.

68
00:04:12,180 --> 00:04:13,050
And there we go.

69
00:04:13,050 --> 00:04:15,880
We got the message displayed correctly.

70
00:04:15,900 --> 00:04:17,760
Form submitted successfully.

71
00:04:18,300 --> 00:04:20,880
And let's check DB.

72
00:04:21,029 --> 00:04:22,590
I'll do a refresh here.

73
00:04:22,710 --> 00:04:23,670
So there we go.

74
00:04:23,670 --> 00:04:25,320
We have another entry.

75
00:04:27,840 --> 00:04:28,820
Right.

76
00:04:28,860 --> 00:04:31,770
If you refresh the page, that message should go.

77
00:04:31,770 --> 00:04:34,590
So now you can fill in the data again.

78
00:04:34,590 --> 00:04:37,170
And yeah, that concludes this video.

79
00:04:37,200 --> 00:04:44,790
We were able to store the data in the database with this line and also show a message with this line.

80
00:04:44,910 --> 00:04:49,650
Next is we want to send out an email.

81
00:04:49,650 --> 00:04:52,830
So let's do that in the next videos.

82
00:04:52,830 --> 00:04:54,320
So thanks for following so far.

83
00:04:54,330 --> 00:04:57,420
I hope you're enjoying this and I'll see you in the next videos.

84
00:04:57,450 --> 00:04:57,720
See you.

