# books/models.py
class Book(models.Model):
title = models.CharField(max_length=100)
isbn = models.CharField(max_length=100, unique=True)
is_published = models.BooleanField(default=True)
def __str__(self):
return self.title
# books/forms.py
class BookCreateForm(forms.ModelForm):
class Meta:
model = Book
class YourForm(ModelForm):
class Meta:
model = YourModel
fields = ['pub_date', 'headline', 'content', 'reporter']
>>> from django.forms import ModelForm
>>> from myapp.models import Article
# Create the form class.
>>> class ArticleForm(ModelForm):
... class Meta:
... model = Article
... fields = ['pub_date', 'headline', 'content', 'reporter']
# Creating a form to add an article.
>>> form = ArticleForm()
# Creating a form to change an existing article.
>>> article = Article.objects.get(pk=1)
>>> form = ArticleForm(instance=article)