Django Insert Data
Learn all about Django Insert Data in this comprehensive tutorial.
- •The Members table created in the previous chapter is empty.
- •You can add multiple records by making a list of Member objects, and execute .
Add Records
The Members table created in the previous chapter is empty.
We will use the Python interpreter (Python shell) to add some members to it.
To open a Python shell, type this command:
Now we are in the shell, the result should be something like this:
At the bottom, after the three >>> write the following:
Hit [enter] and write this to look at the empty Member table:
This should give you an empty QuerySet object, like this:
A QuerySet is a collection of data from a database.
Read more about QuerySets in the Django QuerySet chapter.
Add a record to the table, by executing these two lines:
Execute this command to see if the Member table got a member:
Hopefully, the result will look like this:
Add Multiple Records
You can add multiple records by making a list of Member objects, and execute .save() on each entry:
Hit [enter] one more time at the end to exit the for loop.
Now, if you run this command:
you will see that there are 6 members in the Member table:
Module quiz
2 questionsWhich of the following is true about Django Insert Data?
What is the most common pitfall when working with Django Insert Data?
Answer all questions to submit.