views:

33

answers:

1

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.

A: 

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.

Bartek
Bartek, thanks for your help. I was hoping to have two signup "routes"; TWO BUTTONS with something like 'consultants, get started here' and 'companies, get started here' but ONE VIEW. I was having each take the person to a separate view. This didn't seem django-y to me. I'd like one view that figures out which button was pressed and selects the user_type or group based off of that. I tried using the button value or name, and looking for that in the request.POST information, but couldn't find it.
Tim