adding data:
As long as you create an object model and then use ORM ORM model call this save
method can save the
sample code as follows:
book = Book(name='西游记',author='吴承恩',price=100)
book.save()
Find data
All work is used to find the model objects
attributes to complete the course, the query object can customize the function of this part will be mentioned later...
1. The primary lookup key: the primary key may be used to find objects.get
a method of and. transmission pk=xx
mode to find the following sample code:
book = Book.objects.get(pk=2)
2. The other fields Find: use objects.filter
method to find the following sample code:
books = Book.objects.filter(name='三国演义')
Using the filter
method is a return to QuerySet
the object. This object is similar to the list. We can use this object first
methods to get the first value.
delete data:
First, find the corresponding data model. Then execute this model delete
method to delete. Sample code is as follows:
book = Book.objects.get(pk=1)
book.delete()
change the data:
First, find the corresponding data model. Then modify the value of the property on the model. Then execute save
method to complete the modification. Sample code is as follows:
book = Book.objects.get(pk=2)
book.price = 200
book.save()