Search
 
SCRIPT & CODE EXAMPLE
 

PYTHON

django queryset to form

>>> 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)
Comment

PREVIOUS NEXT
Code Example
Python :: pd.read_csv 
Python :: index a dictionary python 
Python :: how to make exe from.py file 
Python :: np.multiply 
Python :: sort rows by values dataframe 
Python :: python fill zeros left 
Python :: pandas convert numbers in parentheses to negative 
Python :: copy files to a directory using text file 
Python :: How to Merge train and Test dataset in python 
Python :: how to check substring in python 
Python :: python f string 2 decimals 
Python :: dir() in python 
Python :: pandas swapaxes example 
Python :: flatten tf keras 
Python :: how to convert python input to int 
Python :: python see if a number is greater than other 
Python :: how to sort dict by value 
Python :: python cache 
Python :: python use functions from another file 
Python :: python last n array elements 
Python :: pandas create a new column based on condition of two columns 
Python :: check if numpy array contains only duplicates 
Python :: how to extract domain name from url python 
Python :: reverse a string python 
Python :: pandas -inf and inf to 0 
Python :: for in python 
Python :: get user django 
Python :: sample logistic regression parameters for gridsearchcv 
Python :: # find out indexes of element in the list 
Python :: Check if the url is reachable or not in Python 
ADD CONTENT
Topic
Content
Source link
Name
7+1 =