December 2016
Beginner to intermediate
694 pages
14h 2m
English
To save changes to an object that's already in the database, use save().
Given a Blog instance b5 that has already been saved to the database, this example changes its name and updates its record in the database:
>>> b5.name = 'New name' >>> b5.save()
This performs an UPDATE SQL statement behind the scenes. Django doesn't hit the database until you explicitly call save().
Updating a ForeignKey field works exactly the same way as saving a normal field-simply assign an object of the right type to the field in question. This example updates the blog attribute of an Entry instance entry, assuming appropriate instances of Entry, and Blog are already saved to the database (so we can ...
Read now
Unlock full access