Monday, November 23, 2009

Re: accessing pk of an existing object in ModelForm

Daniel Roseman wrote:
> On Nov 23, 2:57 pm, hg7581 <gregor.kl...@dvz.fh-giessen.de> wrote:
>
>> 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
>>
>
> Why not just use self.instance?
>
ahm. Good point.
But what I mean is, if this a safe access respective to the public api.

gregor
> --
> DR.
>
> --
>
> 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=.
>
>
>

--

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