Question

I'm developing a Django app with these models:

class GenericUser(AbstractBaseUser, PermissionsMixin):
    email = models.EmailField(max_length=254, unique=True)
    ....

class Usertype1(GenericUser):
    phone = models.CharField(max_length=20, blank=False)
    ....

class Usertype2(GenericUser):
    mobile = models.CharField(max_length=20, blank=False)
    ....

I'm using django-registration. Every user has their own register template, and I've already solved that. The GenericUser only has basic common fields and doesn't have any registration template. I'm using it as the main Auth model.

The problem comes when I try to register as a new user of Usertype1 or Usertype2. Django falls back and creates a new GenericUser element, without doing anything in the Usertype1/2 tables. My question is: Do I need to do something else to create the Usertype registers? I think I'm missing something.

Was it helpful?

Solution

Django only supports one authentication user. The best solution to your situation is to use the default user with two fields:

phone = models.CharField(max_length=20, blank=False)
mobile = models.CharField(max_length=20, blank=False)

and make a form to validate that you need either phone or mobile. Another option is to have:

phone = models.CharField(max_length=20, blank=False)
is_mobile = models.BoleanField()

and use is_mobile to ask whether the user is using phone or mobile.

More specific situations have to be address in a similar way.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top