1>>> from django.forms import ModelForm
2>>> from myapp.models import Article
3
4# Create the form class.
5>>> class ArticleForm(ModelForm):
6... class Meta:
7... model = Article
8... fields = ['pub_date', 'headline', 'content', 'reporter']
9
10# Creating a form to add an article.
11>>> form = ArticleForm()
12
13# Creating a form to change an existing article.
14>>> article = Article.objects.get(pk=1)
15>>> form = ArticleForm(instance=article)
16
1class YourForm(ModelForm):
2 class Meta:
3 model = YourModel
4 fields = ['pub_date', 'headline', 'content', 'reporter']