2

I am trying to create a custom signup, filling fields of a Profile model that has a OneToOne relation to User. My form is displayed correctly but saving leads to nothing but a page refresh. Using the standard form coming with django-allauth works though.

In my forms.py I have a custom form that uses def signup(self) as the original creator has posted here. This function also seems to never get called.

settings.py

# allauth settings
SITE_ID = 1
ACCOUNT_LOGIN_ATTEMPTS_LIMIT = 5

ACCOUNT_USER_MODEL_USERNAME_FIELD = 'username'
ACCOUNT_USERNAME_REQUIRED = False

ACCOUNT_AUTHENTICATION_METHOD = "email"
ACCOUNT_EMAIL_REQUIRED = True
ACCOUNT_EMAIL_VERIFICATION = "mandatory"

ACCOUNT_FORMS = {'signup': 'accounts.forms.SignupForm'}

forms.py

class SignupForm(forms.ModelForm):

    email = forms.EmailField(widget=forms.TextInput(
        attrs={'type': 'email',
               'placeholder': _('E-mail address')}))
    password1 = PasswordField(label=_("Password"))
    password2 = PasswordField(label=_("Password (again)"))

    class Meta:
        model = Profile
        fields = '__all__'


    def signup(self, request, user):
        print "hi"
        print request.POST
        print user
        new_profile = Profile()
        new_profile.user = user
        new_profile['field1'] = self.cleaned_data['field1']
        new_profile['field2'] = self.cleaned_data['field2']

models.py

class Profile(models.Model):

    user = models.OneToOneField(User)

    field1 = models.CharField(max_length=255)
    field2 = models.CharField(max_length=255)
Community
  • 1
  • 1
Hi Hi
  • 366
  • 4
  • 20

1 Answers1

0

you need to call save() in the end

def signup(self, request, user):
        .....
        new_profile.save()
a7me3D
  • 49
  • 7