On Oct 9, 11:03 am, "british.assassin" <british.assas...@gmail.com> wrote: > Hi, > > I am trying to add some more fields for new members to fill in on > registration to my site by subclassing the RegistrationForm from the > django-registration app. My question is: is there away to do > something like this for saving: > > class PlayerRegistrationForm(RegistrationForm): > first_name = forms.CharField(max_length=100,error_messages= > {'required': u"You must enter your first name"} > last_name = forms.CharField(max_length=100,error_messages= > {'required': u"You must enter your last name"} > phone = forms.CharField(max_length=12,error_messages={'required': > u"You must enter your phone number"}) > > def save(self): > user = super(PlayerRegistrationForm, self).save() > user.first_name = self.cleaned_data['first_name'] > user.first_name = self.cleaned_data['last_name'] > PlayerProfile(user = user, phone = self.cleaned_data['phone']) > return user > > Or would I basically have to re-write the original save function? > > Because when I try my code above I get the follwing error: save() got > an unexpected keyword argument 'profile_callback' > > Or have I just done something wrong? > > Any help would be appreciated. > > Thanks, > > Ryan
Your overridden method always needs to accept the same parameters as the original - apparently this includes a 'profile_callback' keyword argument. You can copy the signature from the parent class, but the easiest thing to do is to always accept *args and **kwargs: def save(self, *args, **kwargs): user = super(PlayerRegistrationForm, self).save(*args, **kwargs) ...etc... I would note separately that your function wouldn't really work. You don't save the changes to the user instance, and you don't save the new PlayerProfile object either, so it is simply thrown away when the function ends. Also, one of the things that can be passed as an argument to a form save is commit=False, so your code needs to take account of that. -- 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+unsubscr...@googlegroups.com For more options, visit this group at http://groups.google.com/group/django-users?hl=en -~----------~----~----~----~------~----~------~--~---