Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to make multiple user types when signing up?

I'm using Django 1.2 and I want to have two user types (one for companies and one for consultants). I will either use an object in my model (something like a boolean for is_company or is_consultant) or Django's groups to distinguish them--depending on which is easier for this problem. I guess it wouldn't be much of a problem if I weren't a total noob ;)

I'm using django-registration for my authentication backend, and I will have a separate form on my webpage for each user type (company vs consultant). I don't think it is best to create two different views that are almost identical for the two cases, so I'm wondering what the best way is to identify/register the users who signed up as either of the two types.

Thanks for your help.

like image 671
Tim Avatar asked Oct 26 '22 11:10

Tim


1 Answers

Do you want the user to pick if they are a consultant or company when registering? If so, you can create your own form by subclassing the RegistrationForm and then passing your new form into the parameters for django-registration (Read the doc on how to do that.)

To subclass the form and add the additional field you would do something like so:

from registration.forms import RegistrationForm

USER_TYPES = (
   ('consultant', 'Consultant'),
   ('company', 'Company'),
)

class MyRegistrationForm(RegistrationForm):
     user_type = forms.ChoiceField(choices=USER_TYPES)

From then, you should catch the signal and do as you need with the form data django-registration has great documentation

Hope that's what you were lookign for.

like image 187
Bartek Avatar answered Nov 18 '22 11:11

Bartek