Monday, November 23, 2009

accessing pk of an existing object in ModelForm

Hello there,
For doing some sanity checks, I need the primary key (pk) of an
(already existing) object in a ModelForm.

What works for me in the meantime, ist the following (admin interface):

class NF(ModelForm):
def __init__(self,*args,**kwargs):
self._args = args
self._kwargs = kwargs
super(NF,self).__init__(*args,**kwargs)

class NA(ModelAdmin):
form = NF

and deeper in the underground in a method
I use the following for the checks.
self._kwargs.has_key('instance'):
pk = self._kwargs['instance'].pk

Now the question. Is there a more canonical form of accessing
this data ?

thanks
gregor

--

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+unsubscribe@googlegroups.com.
For more options, visit this group at http://groups.google.com/group/django-users?hl=.

0 Comments:

Post a Comment

Subscribe to Post Comments [Atom]

<< Home


Real Estate