I'm developing a Django app with these models:
我正在开发这些模型的Django应用程序:
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.
我正在使用django-registration。每个用户都有自己的注册模板,我已经解决了这个问题。 GenericUser仅具有基本公共字段,并且没有任何注册模板。我正在使用它作为主要的Auth模型。
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.
当我尝试注册为Usertype1或Usertype2的新用户时出现问题。 Django退回并创建一个新的GenericUser元素,而不在Usertype1 / 2表中做任何事情。我的问题是:我是否需要做其他事来创建Usertype寄存器?我想我错过了一些东西。
1 个解决方案
#1
1
Django only supports one authentication user. The best solution to your situation is to use the default user with two fields:
Django仅支持一个身份验证用户。您的情况的最佳解决方案是使用具有两个字段的默认用户:
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.
并使用is_mobile询问用户是使用手机还是手机。
More specific situations have to be address in a similar way.
必须以类似的方式解决更具体的情况。
#1
1
Django only supports one authentication user. The best solution to your situation is to use the default user with two fields:
Django仅支持一个身份验证用户。您的情况的最佳解决方案是使用具有两个字段的默认用户:
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.
并使用is_mobile询问用户是使用手机还是手机。
More specific situations have to be address in a similar way.
必须以类似的方式解决更具体的情况。