#100DaysOfWeb in Python Transcripts
Chapter: Days 45-48: Build a simple Django app
Lecture: Create a Django form

Login or purchase this course to watch this video and the rest of the course contents.
0:01 Next we're going to use Django's ModelForm class. And this will be a short video. So it will be pretty easy to set up.
0:11 Because the form we can just model after our quote model. So let's open both. First I need to import ModelForm.
0:34 I need to import my model. Which you see here. Then I'm going to inherit the ModelForm to make my own.
0:54 And I'm going to make a meta class. Now don't worry, you don't need to know meta programing. I also need to define a model and the fields.
1:02 And they magically will later work when I use this quote form in the views. I'm going to reference Quote model. And I'm going to define fields
1:14 that need to show up in the form.
1:33 Notice that I don't specify edit and edited because the auto_now_add and the auto_now attributes will update those fields automatically.
1:42 So I only need quote, author, source, and cover as the fields of my form. And this is a bit abstract. I cannot show it in action until we get
1:52 to the views, which is in the next video. But this is all there is to define a form in Django.


Talk Python's Mastodon Michael Kennedy's Mastodon