As you can imagine i'm new to django. İ tried to use allauth package for signup-in issues. After studying bunch of basic tutorials etc. the basic configuration started to function just fine but i needed custom signup process for my project.
So i started to dig more and implemented this topic to my code -- [1]: django-allauth: custom user generates IntegrityError at /accounts/signup/ (custom fields are nulled or lost)
After the implementation i started to debug various issues caused by django-version difference but eventually i ve got the following error:
TypeError at /accounts/signup/
signup() missing 1 required positional argument: 'model'
Request Method: POST
Request URL: http://localhost:8000/accounts/signup/
Django Version: 3.2.3
Exception Type: TypeError
Exception Value:
signup() missing 1 required positional argument: 'model'
the topics and pastebin links that i've found are not working anymore. thats why i'm stucked with this error. i think im missing something basic but cant figure it out. Here are my model-form-settings and adapters below:
models.py
from djmoney.models.fields import MoneyField
from django.db import models
from django.contrib.auth.models import User
from django_countries.fields import CountryField
from phonenumber_field.modelfields import PhoneNumberField
from django.dispatch import receiver
from django.db.models.signals import post_save
from django.contrib.auth.models import AbstractUser
from django.conf import settings
class CtrackUser(AbstractUser):
date_of_birth = models.DateField(help_text='YYYY-MM-DD format')
country = CountryField()
phone_number = PhoneNumberField()
is_admin = models.BooleanField(default=False)
created = models.DateTimeField(auto_now_add=True)
modified = models.DateTimeField(auto_now=True)
forms.py
from django import forms
from django_countries.fields import CountryField
from APP.models import CtrackUser
from django.conf import settings
from django.contrib.auth import get_user_model
from allauth.account.forms import SetPasswordField,PasswordField
from django.db import models
from APP.models import CtrackUser
from phonenumber_field.modelfields import PhoneNumberField
class SignupForm(forms.Form):
email = forms.EmailField(required=True,)
username = forms.CharField(max_length=80,required=True,)
password1 = SetPasswordField()
password2 = PasswordField()
first_name = forms.CharField(max_length=100,required=False,)
last_name = forms.CharField(max_length=100, required=False,)
date_of_birth = forms.DateField()
country = CountryField().formfield()
phone_number = PhoneNumberField().formfield()
class Meta:
model = get_user_model()
fields = ('email', 'username', 'password1', 'password2', 'first_name', 'last_name',
'date_of_birth', 'gender', 'country','phone_number')
def signup(self, request, user, model):
user.username = self.cleaned_data['username']
user.first_name = self.cleaned_data['first_name']
user.last_name = self.cleaned_data['last_name']
model.date_of_birth = self.cleaned_data['date_of_birth']
model.country = self.cleaned_data['country']
model.phone_number = self.cleaned_data['phone_number']
model.save()
user.save()
adapter.py
from allauth.account.adapter import DefaultAccountAdapter
class AccountAdapter(DefaultAccountAdapter):
def save_user(self, request, user, form, commit=False):
data = form.cleaned_data
user.email = data.get('email')
user.username = data.get('username')
# all your custom fields
user.date_of_birth = data.get('date_of_birth')
user.first_name = data.get('first_name')
user.last_name = data.get('last_name')
user.country = data.get('country')
user.phonenumber = data.get('phonenumber')
if 'password1' in data:
user.set_password(data["password1"])
else:
user.set_unusable_password()
self.populate_username(request, user)
if commit:
user.save()
return user
settings.py
ACCOUNT_EMAIL_CONFIRMATION_EXPIRE_DAYS=7
ACCOUNT_EMAIL_REQUIRED = True
ACCOUNT_LOGIN_ATTEMPTS_LIMIT = 5
ACCOUNT_LOGOUT_REDIRECT_URL ='/accounts/login/'
LOGIN_REDIRECT_URL = '/profile'
ACCOUNT_EMAIL_VERIFICATION = True
EMAIL_BACKEND = 'django.core.mail.backends.console.EmailBackend'
ACCOUNT_AUTHENTICATION_METHOD = 'username_email'
ACCOUNT_ADAPTER = 'APP.adapter.MyAccountAdapter'
AUTH_USER_MODEL = "APP.CtrackUser"
ACCOUNT_SIGNUP_FORM_CLASS = 'APP.forms.SignupForm'
ACCOUNT_ADAPTER = 'APP.adapter.AccountAdapter'
SOCIALACCOUNT_QUERY_EMAIL = True
SOCIALACCOUNT_AUTO_SIGNUP = False
ACCOUNT_USER_MODEL_USERNAME_FIELD = 'username'