Data additions and deletions in Django are as follows:
We take a model:user for example, user has three fields, one is username, passwd, PhoneNumber
(1) Add a record
Add a record for the username, passwd, phonenumber field values S_username, S_PASSWD, S_phonenumber
User=user ()
User.username=s_username
user.passwd=s_passwd
User.phonenumber=s_phonenumber
User.save ()
Or
User=user (Username=s_username,passwd=s_passwd,phonenumber=s_phonenumber)
User.save ()
(2) Deleting records
Delete a record of username as ' yy '
User.objects.get (username= ' yy '). Delete ()
Delete a set of records, assuming that a phone number can correspond to more than one user, now remove all users with a phone number of ' 123456 '
User.objects.filter (phonenumber= ' 123456 '). Delete ()
(3) Change of record
Change the phone number of the record username as ' DW ' to ' 88888 '
User=user.objects.get (username= ' DW ')
User.phonenumber= ' 88888 '
User.save ()
(4) Inquiry record
Querying for records with username as ' DW '
User=user.objects.get (username= ' DW '), the record with Get query is a User object
Query PhoneNumber for all users with ' 88888 '
User=user.objects.filter (phonenumber= ' 88888 ') with the result of the filter query is a list
Copyright NOTICE: This article for Bo Master original article, without Bo Master permission not reproduced.
Add, delete, change, and check the data records in Django