Question about Signals : How to get the Primary Key Value ?

4 views
Skip to first unread message

bino oetomo

unread,
Oct 6, 2011, 5:10:09 AM10/6/11
to django...@googlegroups.com
Dear All ..

From the basic tutorial of "Polls",
I add this lines to model.py
----START--------
from django.db.models.signals import post_save

def do_something(sender, **kwargs):
print "==========START==========="
print "Called by : " , sender
print "This is KWARGS :"
print kwargs
obj = kwargs['instance']
print "This is instances :"
print obj
print "=========DONE============"

post_save.connect(do_something, sender=Poll)
---Stop--

And from the debug console while I add a new record, here is what I got :

==========START===========
Called by : <class 'poll.models.Poll'>
This is KWARGS :
{'raw': False, 'signal': <django.dispatch.dispatcher.Signal object at
0x8ddab6c>, 'instance': <Poll: WhatsUp ?>, 'created': True}
This is instances :
WhatsUp ?
=========DONE============

My question : How to het the primary key of involved object/instance
(the "id" Column in table) ?
When I try to use --> print Poll.id
It raise traceback that state (more/less) : Model 'Poll' have no object
named 'id'

Kindly please give me your enlightment

Sincerely
-bino-

BILLION Sébastien

unread,
Oct 6, 2011, 6:07:03 AM10/6/11
to django...@googlegroups.com
hi,

obj.id ?

BILLION Sébastien

the Answer to the ultimate question of life, the universe and everything is 42

http://www.sebastienbillion.com/

Daniel Roseman

unread,
Oct 6, 2011, 6:11:00 AM10/6/11
to django...@googlegroups.com
The instance is in, well, the `instance` argument. You get it from there.
--
DR. 

bino oetomo

unread,
Oct 6, 2011, 6:29:07 AM10/6/11
to django...@googlegroups.com
On 10/06/2011 05:11 PM, Daniel Roseman wrote:
>
> The instance is in, well, the `instance` argument. You get it from there.
> --
> DR.
>
Thankyou ...
I got it by ---> print obj.pk

Sincerely
-bino-

Reply all
Reply to author
Forward
0 new messages