django queryset to form

Solutions on MaxInterview for django queryset to form by the best coders in the world

showing results for - "django queryset to form"
Nick
25 Feb 2017
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