Hi Emily,

thanks so far!

unfortunately this line:
> instance = getattr(kwargs, 'instance')
throws this error:
> Exception Value: 'dict' object has no attribute 'instance'

what next?

On Aug 14, 1:52 pm, Emily Rodgers <emily.kate.rodg...@googlemail.com>
wrote:
> On Aug 14, 12:14 pm, Léon Dignòn <leon.dig...@gmail.com> wrote:
>
>
>
>
>
> > Hi,
>
> > I try override a ModelForms init to claim the variable instance. After
> > that I call super.__init__().
> > It's almost working, but there is no form shown in the browser.  Any
> > ideas what might be wrong?
>
> > class ProfileForm(ModelForm):
> >     first_name = forms.CharField(required=False, max_length=30)
> >     last_name = forms.CharField(required=False, max_length=30)
>
> >     class Meta:
> >         model = UserProfile
> >         exclude = ('user',) # User will be filled in by the view.
>
> >     def __init__(self, data=None, files=None, auto_id='id_%s',
> > prefix=None, initial=None,
> >                  error_class=None, label_suffix=':',
> > empty_permitted=False, instance=None):
> >         f = open('debug.txt', 'w')
> >         f.write("%s \n\n-----\n\n" % instance.user.first_name) # Bob
> >         f.write("%s \n\n-----\n\n" % instance.user.last_name) # Marley
> >         super(ProfileForm, self).__init__(data, files, auto_id,
> > prefix, initial, error_class, label_suffix, empty_permitted, instance)
>
> Rather than listing all the key word arguments (kwargs) like that, you
> are better doing it like this:
>
> import logging # probably a better way than writing to debug.txt, but
> clearly it is personal choice
>
> def __init__(self, *args, **kwargs):
>     instance = getattr(kwargs, 'instance')
>     logging.debug("First name: %s" % instance.user.first_name) # I
> like to know what it thinks it is printing!
>     logging.debug("Last name: %s" % instance.user.last_name) #
> obviously you can change str if you like
>     super(ProfileForm, self).__init__(data, *args, **kwargs)
>
> I don't know if this will fix your problem (hard to say without
> visibility of the view), but it may be that you have forgotten one of
> the kwargs. If you want to add extra parameters, or set them to
> specific values you can still do this before calling init.
>
> HTH,
> Em- Hide quoted text -
>
> - Show quoted text -
--~--~---------~--~----~------------~-------~--~----~
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+unsubscr...@googlegroups.com
For more options, visit this group at 
http://groups.google.com/group/django-users?hl=en
-~----------~----~----~----~------~----~------~--~---

Reply via email to