NOTE
This file was generated by Descript <www.descript.com>
1

00:00:00,083  -->  00:00:01,643
Hi guys, and welcome back.

2

00:00:01,733  -->  00:00:05,693
So far the entries have been
formatted incorrectly on our website.

3

00:00:05,693  -->  00:00:09,113
So in this video, let's learn how
we can format them in a different

4

00:00:09,113  -->  00:00:11,093
way using our Python code.

5

00:00:11,393  -->  00:00:12,293
So let's get to it.

6

00:00:13,054  -->  00:00:15,934
Let's begin by reformatting these dates.

7

00:00:15,994  -->  00:00:20,794
Note that in our entries list, we're
storing strings that's because we

8

00:00:20,794  -->  00:00:24,334
are getting the current dates when we
create an entry and we're formatting

9

00:00:24,334  -->  00:00:26,464
it as a string using this format.

10

00:00:26,862  -->  00:00:30,282
What we want to do before we show
the entries in our template is

11

00:00:30,282  -->  00:00:34,632
we want to make sure this date
matches the format that we wanted.

12

00:00:35,153  -->  00:00:37,402
So we do entries with dates.

13

00:00:37,738  -->  00:00:40,018
Is going to be equal to this list.

14

00:00:40,618  -->  00:00:44,978
And in the list, we're going
to have entry zero, entry one,

15

00:00:45,248  -->  00:00:46,928
which is the date in this format.

16

00:00:47,228  -->  00:00:52,028
And we're also going to have the new
date format that we want for our entries.

17

00:00:52,478  -->  00:00:55,568
The reason why we want the date
in two different formats will

18

00:00:55,568  -->  00:00:57,008
become clear in just a moment.

19

00:00:57,526  -->  00:00:59,866
How do we reformat the date?

20

00:00:59,896  -->  00:01:03,946
The first thing we have to do is we
have to tell Python to understand

21

00:01:03,976  -->  00:01:07,556
this date so that it can then
reformat it into something else.

22

00:01:08,036  -->  00:01:13,746
So we'll do datetime.datetime.strptime
and we would pass in entry one.

23

00:01:14,273  -->  00:01:19,103
And then in here, we're going to pass in
the format of the string at the moment.

24

00:01:19,103  -->  00:01:22,193
So that's %Y %m %d.

25

00:01:22,626  -->  00:01:24,396
What this is going to do is
it's going to tell Python.

26

00:01:24,456  -->  00:01:27,996
Okay, this is the dates that we're talking
about, and it's going to understand

27

00:01:27,996  -->  00:01:30,516
it as a date and not as a string.

28

00:01:30,976  -->  00:01:32,836
I'm just going to reformat
this a little bit better.

29

00:01:32,896  -->  00:01:33,946
So you guys can see.

30

00:01:34,450  -->  00:01:42,670
We can then go ahead and do
strftime and format it as %b %d.

31

00:01:43,030  -->  00:01:48,940
And this is going to reformat it as
October 10, for example, or November 11.

32

00:01:49,490  -->  00:01:53,570
Of course we want to do this for
every entry in the entries list.

33

00:01:53,570  -->  00:01:56,330
So we'll do for entry in entries.

34

00:01:56,820  -->  00:01:57,420
Just like that.

35

00:01:57,660  -->  00:02:00,840
And now we're going to pass in
the entries with date in here.

36

00:02:01,050  -->  00:02:03,000
Keeping entries as it is.

37

00:02:03,519  -->  00:02:07,089
Let's save that and go over to the
template because now instead of entry

38

00:02:07,089  -->  00:02:09,959
one here, we want to display entry two.

39

00:02:10,359  -->  00:02:15,159
That is the properly formatted date
string, but we still want to use

40

00:02:15,159  -->  00:02:19,299
entry one in here for the datetime
attributes of the time element.

41

00:02:19,499  -->  00:02:21,779
So we will do entry one.

42

00:02:22,290  -->  00:02:25,770
This is going to make sure that any
accessibility software will still

43

00:02:25,770  -->  00:02:27,750
understand this as being the correct date.

44

00:02:28,050  -->  00:02:32,760
While showing a nicer way of
displaying the date in text.

45

00:02:33,283  -->  00:02:35,473
Let's run this and see what happens.

46

00:02:35,979  -->  00:02:38,319
And you can see now we get November 13th.

47

00:02:38,834  -->  00:02:44,317
If we write something a little bit longer,
like this one, we'll get a truncated title

48

00:02:44,347  -->  00:02:46,807
at the top with the ellipsis at the end.

49

00:02:46,957  -->  00:02:49,357
That's because we've got
true there in our filter.

50

00:02:49,807  -->  00:02:51,607
And then we've got the
complete text at the bottom.

51

00:02:52,233  -->  00:02:52,443
All right.

52

00:02:52,443  -->  00:02:56,403
So I think we've solved pretty much
every problem that we need so far.

53

00:02:56,433  -->  00:02:59,583
The next step is to start using MongoDB.

54

00:03:00,705  -->  00:03:02,145
Thank you guys for
joining me in this video.

55

00:03:02,205  -->  00:03:04,335
I hope you've enjoyed it and
you've learned something.

56

00:03:04,485  -->  00:03:06,075
So I'll see you in the next one.
