Skip to content Skip to sidebar Skip to footer

Django-allauth Multiple Signup Form For Difference User Type

I have already searched all the questions in stackoverflow. However, there is no one clearly answered this question yet. My application contain 2 user types, I added 2 user profile

Solution 1:

try this model which will make the common profile (If choices are same for both model)

Model

class Profile(models.Model):
    TYPE_CHOICES = (
        ('SUP', 'Supplier'),
        ('DIS', 'Distributer'),
    )
    type = models.CharField(max_length=3, choices=TYPE_CHOICES)
    user = models.OneToOneField(User, on_delete=models.CASCADE)
    #bio = models.TextField(max_length=500, blank=True)
    nationality = CountryField()
    company = models.CharField(max_length=50, unique=True, null=True, blank=True, default=None)
    phone = models.CharField(max_length=50, unique=True, null=True, blank=True, default=None)
    skype = models.CharField(max_length=50, unique=True, null=True, blank=True, default=None)
    address = models.CharField(max_length=50, unique=True, null=True, blank=True, default=None)

Form

class SignUpForm(SignupForm):
    type = forms.CharField(
    max_length=3,
    widget=forms.Select(choices=TYPE_CHOICES ),
    ) 
    first_name = forms.CharField(max_length=30, label='First name', required=False)
    last_name = forms.CharField(max_length=30, label='Last name', required=False)
    company = forms.CharField(max_length=50, required=True, strip=True)
    phone = forms.CharField(max_length=50, required=True, strip=True)
    skype = forms.CharField(max_length=50, required=True, strip=True)
    address = forms.CharField(max_length=50, required=True, strip=True)

    def save(self, request):
        user = super(SignUpForm, self).save(request)
        advertiser_user.save()
        user.account_type = 1
        user.save()
        return user

Post a Comment for "Django-allauth Multiple Signup Form For Difference User Type"