0

I customized the user profile like suggested in this question: How to customize user profile when using django-allauth

So basically my code looks like this:

  • In forms.py:

    class SignupForm(forms.Form):
        first_name = forms.CharField(max_length=30, label=_("First Name"))
        last_name = forms.CharField(max_length=30, label=_("Last Name"))
    
        def save(self, user):
            user.first_name = self.cleaned_data['first_name']
            user.last_name = self.cleaned_data['last_name']
            user.save()
    
  • In settings.py:

    ACCOUNT_SIGNUP_FORM_CLASS = 'core.forms.SignupForm'
    

The code works fine and I get the complete form with First Name and Last Name in the sign up form, but I get the following warning:

DeprecationWarning: The custom signup form must offer a def signup(self, request, user) method DeprecationWarning)

Question: What do I have to do with def signup(self, request, user) method in order to solve this warning?

Thank you!

Community
  • 1
  • 1
ferrangb
  • 2,012
  • 2
  • 20
  • 34
  • Ok, but what do I have to put inside it? What does it has to do? Could you post an example please? Thanks! :) – ferrangb Jun 15 '14 at 15:50

1 Answers1

1

As stated in docs the deprecation warning in favor of def signup(self, request, user):

Previously, the save(user) was called on the custom signup form. However, this shadowed the existing save method in case a model form was used. To avoid confusion, the save method has been deprecated in favour of a def signup(request, user) method.

So just implement the method. And do what ever you were doing in def save() in def signup() There is no need of def save().

def signup(self, request, user):
    user.first_name = self.cleaned_data['first_name']
    user.last_name = self.cleaned_data['last_name']
    user.save()
Aamir Rind
  • 38,793
  • 23
  • 126
  • 164