Django — Get an objects Primary Key

Somebody asked on #Django IRC: what is an easy way to get an objects primary key? I was shocked to hear he couldn’t find it on google.. and I guess it’s true. This is probably the very first stepping stone in learning Django.

I say: Do the Django Tutorials, they are short, well written, and fun!
Besides, its got a hassle-free return policy (90 days).

Well, uh…
object_instance.id = your primary key

Wait… I was wrong. here’s an update from SmileyChris:

Actually, object_instance.pk would be more correct. “id” is just the default primary key field, whereas “pk” is an alias to the field which is defined as the primary key.

5 thoughts on “Django — Get an objects Primary Key

  1. Actually, object_instance.pk would be more correct. “id” is just the default primary key field, whereas “pk” is an alias to the field which is defined as the primary key.

  2. A diamond engagement ring is the must-have clinhcher for a man wanting to hear her say “Yes. It is universal fact that most of the women of the world love to receive a beautiful diamond engagement rings on her very special and auspicious occasion that is engagement for which she would have shape beautiful dreams and also planned for many thing for that particular occasion. Inspired by these classic masterpieces the Heart shaped diamond engagement rings are available in enthralling red, blue and pure colorless beauty.

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s