#100DaysOfWeb in Python Transcripts
Chapter: Days 45-48: Build a simple Django app
Lecture: Create a Django form
0:01 Next we're going to use Django's
0:03 ModelForm class.
0:05 And this will be a short video.
0:07 So it will be pretty easy to set up.
0:10 Because the form we can just model
0:11 after our quote model.
0:15 So let's open both.
0:23 First I need to import ModelForm.
0:33 I need to import my model.
0:38 Which you see here.
0:43 Then I'm going to inherit the ModelForm
0:46 to make my own.
0:53 And I'm going to make a meta class.
0:55 Now don't worry, you don't need
0:56 to know meta programing.
0:58 I also need to define a model and the fields.
1:01 And they magically will later work when I
1:03 use this quote form in the views.
1:07 I'm going to reference Quote model.
1:11 And I'm going to define fields
1:13 that need to show up in the form.
1:32 Notice that I don't specify edit and edited
1:35 because the auto_now_add and the auto_now
1:37 attributes will update those fields automatically.
1:41 So I only need quote, author, source, and cover
1:44 as the fields of my form.
1:48 And this is a bit abstract.
1:49 I cannot show it in action until we get
1:51 to the views, which is in the next video.
1:54 But this is all there is to define a form in Django.