All language subtitles for 004 Author Model & one-to-many_en

af Afrikaans
sq Albanian
am Amharic
ar Arabic
hy Armenian
az Azerbaijani
eu Basque
be Belarusian
bn Bengali
bs Bosnian
bg Bulgarian
ca Catalan
ceb Cebuano
ny Chichewa
zh-CN Chinese (Simplified)
zh-TW Chinese (Traditional)
co Corsican
hr Croatian
cs Czech
da Danish
nl Dutch
en English
eo Esperanto
et Estonian
tl Filipino
fi Finnish
fr French
fy Frisian
gl Galician
ka Georgian
de German
el Greek
gu Gujarati
ht Haitian Creole
ha Hausa
haw Hawaiian
iw Hebrew
hi Hindi
hmn Hmong
hu Hungarian
is Icelandic
ig Igbo
id Indonesian
ga Irish
it Italian
ja Japanese
jw Javanese
kn Kannada
kk Kazakh
km Khmer
ko Korean
ku Kurdish (Kurmanji)
ky Kyrgyz
lo Lao
la Latin
lv Latvian
lt Lithuanian
lb Luxembourgish
mk Macedonian
mg Malagasy
ms Malay
ml Malayalam
mt Maltese
mi Maori
mr Marathi
mn Mongolian
my Myanmar (Burmese)
ne Nepali
no Norwegian
ps Pashto
fa Persian Download
pl Polish
pt Portuguese
pa Punjabi
ro Romanian
ru Russian
sm Samoan
gd Scots Gaelic
sr Serbian
st Sesotho
sn Shona
sd Sindhi
si Sinhala
sk Slovak
sl Slovenian
so Somali
es Spanish
su Sundanese
sw Swahili
sv Swedish
tg Tajik
ta Tamil
te Telugu
th Thai
tr Turkish
uk Ukrainian
ur Urdu
uz Uzbek
vi Vietnamese
cy Welsh
xh Xhosa
yi Yiddish
yo Yoruba
zu Zulu
or Odia (Oriya)
rw Kinyarwanda
tk Turkmen
tt Tatar
ug Uyghur
Would you like to inspect the original subtitles? These are the user uploaded subtitles that are being translated: 1 00:00:02,240 --> 00:00:04,680 So besides the post model, which of course 2 00:00:04,680 --> 00:00:07,494 is the most important model for this website 3 00:00:07,494 --> 00:00:10,230 we also wanna have authors. 4 00:00:10,230 --> 00:00:12,090 We wanna have an author model 5 00:00:12,090 --> 00:00:15,950 and we wanna set it up as the find on this slide, 6 00:00:15,950 --> 00:00:18,680 hence, back in the models.py file, 7 00:00:18,680 --> 00:00:23,410 we can add class, author, and extend models.model 8 00:00:25,030 --> 00:00:27,710 And here I now I wanna set up a first name, 9 00:00:27,710 --> 00:00:31,415 which is a CharField with a max length of, 10 00:00:31,415 --> 00:00:34,060 let's say 100 11 00:00:35,620 --> 00:00:39,853 and basically repeat this for the last name as well. 12 00:00:40,840 --> 00:00:43,660 And then let's also add the email address. 13 00:00:43,660 --> 00:00:44,590 And for this, 14 00:00:44,590 --> 00:00:46,950 we could add another CharField 15 00:00:46,950 --> 00:00:49,925 since the email address is just text in the end, 16 00:00:49,925 --> 00:00:53,260 but conveniently Django has an email field, 17 00:00:53,260 --> 00:00:54,510 which we can use instead. 18 00:00:56,428 --> 00:00:59,440 And again, if we search for email field here 19 00:00:59,440 --> 00:01:00,642 to read more about that, 20 00:01:00,642 --> 00:01:03,300 we see that in the end, this is a CharField, 21 00:01:03,300 --> 00:01:06,800 which just automatically validates the input 22 00:01:06,800 --> 00:01:09,890 and checks if it is a valid email address. 23 00:01:09,890 --> 00:01:12,320 So when we later used the admin panel, 24 00:01:12,320 --> 00:01:15,460 we'll automatically get email address validation, 25 00:01:15,460 --> 00:01:17,640 which of course is very convenient. 26 00:01:17,640 --> 00:01:20,140 And if we would try to save data in the database, 27 00:01:20,140 --> 00:01:21,358 which is not an email address, 28 00:01:21,358 --> 00:01:24,690 if we would try to save such data through that model, 29 00:01:24,690 --> 00:01:25,623 it would fail. 30 00:01:26,610 --> 00:01:29,030 So, this is now my author model, 31 00:01:29,030 --> 00:01:32,890 and therefore, it's now time for our first relation. 32 00:01:32,890 --> 00:01:35,070 For this One-to-Many relation, 33 00:01:35,070 --> 00:01:37,773 which we have between author and post. 34 00:01:38,700 --> 00:01:40,270 Now you'll learnt that you can set up 35 00:01:40,270 --> 00:01:41,810 One-to-Many relations 36 00:01:41,810 --> 00:01:45,120 by adding such a foreign key field. 37 00:01:45,120 --> 00:01:47,380 So, here I wanna go to my post, 38 00:01:47,380 --> 00:01:51,300 and add the author field here, 39 00:01:51,300 --> 00:01:54,853 and set these two models or, and key. 40 00:01:56,020 --> 00:01:57,320 And that then allows me 41 00:01:57,320 --> 00:01:59,280 to point at the related model, 42 00:01:59,280 --> 00:02:00,993 which in this case is the author. 43 00:02:02,500 --> 00:02:05,070 This sets up this relation. 44 00:02:05,070 --> 00:02:07,460 Now we also wanna add on delete 45 00:02:07,460 --> 00:02:11,380 to make sure how Django and SQL should behave here. 46 00:02:11,380 --> 00:02:15,110 If we delete an author which was assigned to a post, 47 00:02:15,110 --> 00:02:17,701 and in that case, we probably don't wanna 48 00:02:17,701 --> 00:02:20,500 delete the entire post. 49 00:02:20,500 --> 00:02:23,523 So I will just say models, set, null, 50 00:02:24,640 --> 00:02:27,300 to set the field, 51 00:02:27,300 --> 00:02:29,820 the author field to null, 52 00:02:29,820 --> 00:02:32,053 if we delete a related author, 53 00:02:33,060 --> 00:02:34,600 I also wanna make sure that 54 00:02:34,600 --> 00:02:38,180 when we use the inverse of the relation for querying, 55 00:02:38,180 --> 00:02:41,650 we don't have to work with post underscore set, 56 00:02:41,650 --> 00:02:43,740 but with just posts 57 00:02:43,740 --> 00:02:46,450 therefore I'll set up the related name here 58 00:02:46,450 --> 00:02:49,340 and set this to posts 59 00:02:49,340 --> 00:02:51,150 so that we'll be able to pick an author 60 00:02:51,150 --> 00:02:53,780 and then query for the posts of that author 61 00:02:53,780 --> 00:02:56,690 if we wanted to do that anywhere. 62 00:02:56,690 --> 00:02:59,010 And that's the author model added, 63 00:02:59,010 --> 00:03:01,200 and the first relation set up. 64 00:03:01,200 --> 00:03:03,260 Let's now work on the last model 65 00:03:03,260 --> 00:03:04,693 and the last relation. 4823

Can't find what you're looking for?
Get subtitles in any language from opensubtitles.com, and translate them here.