That kind of surprises me. I thought that the whole code will be
parsed before actually doing something. Like C# :)

But save() is not overridden! If I comment out super() it still saves
the form.
-----
class ProfileFormExtended(UserProfile):
    def save(self, force_insert=False, force_update=False):
            #super(ProfileFormExtended, self).save
(force_insert,force_update)
-----

I have UserProfile(models.Model) defined. Then I inherit this class by
writing ProfileFormExtended(UserProfile) after that I create a
ModelForm class ProfileForm(models.ModelForm) which has a meta
attribute model=ProfileFormExtended which tells the ModelForm to use
the inherited ProfileFormExtended class to create a form. Up to here
it's working.

What it does NOT do is using ProfileFormExtended.save() instead of
UserProfile.save(). And that although it uses ProfileFormExtended.

What am I missing???






On Aug 10, 3:23 am, Malcolm Tredinnick <malc...@pointy-stick.com>
wrote:
> On Sun, 2009-08-09 at 13:35 -0700, Léon Dignòn wrote:
> > Hi,
>
> > I have a ModelForm of my UserProfile model with two additional fields.
> > I need to override save(), to save the additional fields to the
> > django.contrib.auth.model.User model.
> > I tried to do that with a subclass of my UserProfile model class to
> > have the code separated. But I get a NameError: name
> > 'ProfileFormExtended' is not defined.
>
> > from django.contrib.auth.models import User
> > from django.db import models
> > from django.forms.models import ModelForm
> > from django import forms
> > from myproject.myapp.models import UserProfile
>
> > class ProfileForm(ModelForm):
> >     first_name = forms.CharField(max_length=30)
> >     last_name = forms.CharField(max_length=30)
>
> >     class Meta:
> >         model = ProfileFormExtended
>
> At the time this line of code is executed, this class doesn't exist yet
> (you don't define it until later in the file). The error message is
> telling you the right thing. Reorder the code in the file.
>
> Regards,
> Malcolm- 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