Afrikaans
Akan
Albanian
Amharic
Arabic
Armenian
Azerbaijani
Basque
Belarusian
Bemba
Bengali
Bihari
Bosnian
Breton
Bulgarian
Cambodian
Catalan
Cebuano
Cherokee
Chichewa
Chinese (Simplified)
Chinese (Traditional)
Corsican
Croatian
Czech
Danish
Dutch
English
Esperanto
Estonian
Ewe
Faroese
Filipino
Finnish
French
Frisian
Ga
Galician
Georgian
German
Greek
Guarani
Gujarati
Haitian Creole
Hausa
Hawaiian
Hebrew
Hindi
Hmong
Hungarian
Icelandic
Igbo
Indonesian
Interlingua
Irish
Italian
Japanese
Javanese
Kannada
Kazakh
Kinyarwanda
Kirundi
Kongo
Korean
Krio (Sierra Leone)
Kurdish
Kurdish (Soranî)
Kyrgyz
Laothian
Latin
Latvian
Lingala
Lithuanian
Lozi
Luganda
Luo
Luxembourgish
Macedonian
Malagasy
Malay
Malayalam
Maltese
Maori
Marathi
Mauritian Creole
Moldavian
Mongolian
Myanmar (Burmese)
Montenegrin
Nepali
Nigerian Pidgin
Northern Sotho
Norwegian
Norwegian (Nynorsk)
Occitan
Oriya
Oromo
Pashto
Polish
Portuguese (Brazil)
Portuguese (Portugal)
Punjabi
Quechua
Romanian
Romansh
Runyakitara
Russian
Samoan
Scots Gaelic
Serbian
Serbo-Croatian
Sesotho
Setswana
Seychellois Creole
Shona
Sindhi
Sinhalese
Slovak
Slovenian
Somali
Spanish
Spanish (Latin American)
Sundanese
Swahili
Swedish
Tajik
Tamil
Tatar
Telugu
Thai
Tigrinya
Tonga
Tshiluba
Tumbuka
Turkish
Turkmen
Twi
Uighur
Ukrainian
Urdu
Uzbek
Vietnamese
Welsh
Wolof
Xhosa
Yiddish
Yoruba
Zulu
So besides the post model, which of course
is the most important model for this website
we also wanna have authors.
We wanna have an author model
and we wanna set it up as the find on this slide,
hence, back in the models.py file,
we can add class, author, and extend models.model
And here I now I wanna set up a first name,
which is a CharField with a max length of,
let's say 100
and basically repeat this for the last name as well.
And then let's also add the email address.
And for this,
we could add another CharField
since the email address is just text in the end,
but conveniently Django has an email field,
which we can use instead.
And again, if we search for email field here
to read more about that,
we see that in the end, this is a CharField,
which just automatically validates the input
and checks if it is a valid email address.
So when we later used the admin panel,
we'll automatically get email address validation,
which of course is very convenient.
And if we would try to save data in the database,
which is not an email address,
if we would try to save such data through that model,
it would fail.
So, this is now my author model,
and therefore, it's now time for our first relation.
For this One-to-Many relation,
which we have between author and post.
Now you'll learnt that you can set up
One-to-Many relations
by adding such a foreign key field.
So, here I wanna go to my post,
and add the author field here,
and set these two models or, and key.
And that then allows me
to point at the related model,
which in this case is the author.
This sets up this relation.
Now we also wanna add on delete
to make sure how Django and SQL should behave here.
If we delete an author which was assigned to a post,
and in that case, we probably don't wanna
delete the entire post.
So I will just say models, set, null,
to set the field,
the author field to null,
if we delete a related author,
I also wanna make sure that
when we use the inverse of the relation for querying,
we don't have to work with post underscore set,
but with just posts
therefore I'll set up the related name here
and set this to posts
so that we'll be able to pick an author
and then query for the posts of that author
if we wanted to do that anywhere.
And that's the author model added,
and the first relation set up.
Let's now work on the last model
and the last relation.
Can't find what you're looking for?
Get subtitles in any language from opensubtitles.com, and translate them here.