The Django tutorial says in Part 1:

[_Begin Quote_]
# Create a new Poll.
>>> import datetime
>>> p = Poll(question="What's up?", pub_date=datetime.datetime.now())

# Save the object into the database. You have to call save()
explicitly.
>>> p.save()

# Now it has an ID. Note that this might say "1L" instead of "1",
depending
# on which database you're using. That's no biggie; it just means your
# database backend prefers to return integers as Python long integer
# objects.
>>> p.id
1
[_End Quote_]

After calling save() on the model, we see that "Now it has an ID".

So Django is doing an SQL select query, something like last_insert_id,
if I'm not wrong?

I have looked at the source code but it's not entirely clear to me how
Django gets the id for the object that has just been saved.

Any insight into this is greatly appreciated.

Thanks.

--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the Google Groups 
"Django users" group.
To post to this group, send email to django-users@googlegroups.com
To unsubscribe from this group, send email to 
django-users+unsubscr...@googlegroups.com
For more options, visit this group at 
http://groups.google.com/group/django-users?hl=en
-~----------~----~----~----~------~----~------~--~---

Reply via email to