Jump to content

Django for Designers: Difference between revisions

imported>Paulproteus
imported>Paulproteus
(→‎Add some bookmarks via the command line: Improve verbiage around id)
Line 932:
<source lang="python">>>> b.id</source>
 
Python has given you back your prompt because the value of b.id is ''None''. That is because we have not yet saved the object; to the database, it does not exist.
What happens?
 
Save your bookmark to the database. In Django, you have to call save() explicitly.
Line 938:
<source lang="python">>>> b.save()</source>
 
GetNow, try again to get the id of the Bookmark instance. Because it’s been saved, it has an ID in the database now! Even though we didn't specify one in our models.py, every saved model instance automatically has an id field.
 
<source lang="python">>>> b.id
Anonymous user
Cookies help us deliver our services. By using our services, you agree to our use of cookies.