Brilliant! Thanks.

Just to make it clear for anyone else reading, doing self.instance.pk
gives me what I want.

I am not really an expert at any level, have no formal training, and
am just poking around the "dark alley of code" to find my way, so am
just hoping what I am doing is right ;)

Regards,
CM

On Dec 9, 2:50 pm, bruno desthuilliers <bruno.desthuilli...@gmail.com>
wrote:
> On 9 déc, 06:29, chefsmart <moran.cors...@gmail.com> wrote:
>
> > At what point in a modelform's lifecycle does the underlying object
> > become accessible?
> > Specifically, can I access the underlying object in
> > a modelform's "clean" method?
> >  Or is it only after one does form.save
> > () with or without commit = False?
>
> Use the source, Luke !-)
>
> Reading the code for the BaseModelForm class, it appears that if no
> instance is provided (you can obviously access the instance from any
> method if you passed one...), one is created in the __init__ method.
> So you do have access to the instance anywhere after to call to
> ModelForm.__init__.
>
> *BUT*
>
> > I basically need to do some custom validation and need to access the
> > object's pk attribute in "clean". Can this be done?
>
> The pk will only be set if the instance has already been saved at
> least once (stating the obvious, yes). So if you didn't pass an
> instance, the one you'll get will have None as pk value.
>
> HTH

--

You received this message because you are subscribed to the Google Groups 
"Django users" group.
To post to this group, send email to django-us...@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