【发布时间】:2018-02-11 02:31:51
【问题描述】:
我现在很困惑。我在一个项目中有 3 个应用程序。
App1:从最终用户使用(基于 Web 视图的应用)
App2 : 从服务提供商处使用(网络服务)
App3 : 由系统管理员使用。
我想为每个应用程序使用 django 身份验证系统。我可以制作 django 项目来验证 App1 的用户。但是,如何同时使用 App2 和 App3 的认证系统。
当我运行python manage.py createsuperuser 命令时,django 使 App1 成为超级用户。如何使用此命令为 App2 和 App3 制作?
有人知道吗?请帮我。
Models.py
### This table is for end user.
class RemoshinUser(models.Model):
user = models.OneToOneField(User)
user_type = models.SmallIntegerField(default=1)
kana_name = models.CharField(max_length=128, blank=True)
date_of_birth = models.DateField(blank=True, null=True)
sex = models.SmallIntegerField(null=True)
postno = models.CharField(max_length=7, blank=True)
address1 = models.CharField(max_length=128)
address2 = models.CharField(max_length=128, blank=True)
telno = models.CharField(max_length=16, blank=True)
photo = models.ImageField(upload_to='users/%Y/%m/%d', blank=True)
create_date = models.DateTimeField(auto_now_add=True)
modify_date = models.DateTimeField(auto_now=True)
class Meta:
db_table = 'remosys_remoshin_user_tbl'
swappable = 'AUTH_USER_MODEL'
### This table is for service provider.
class RemoshinDoctor(models.Model):
user = models.OneToOneField(User)
user_type = models.SmallIntegerField(default=2)
doctor_id = models.CharField(max_length=16, primary_key=True)
clinic_id = models.ForeignKey(Clinic)
photo = models.ImageField(blank=True, null=True)
create_date = models.DateTimeField(auto_now_add=True)
modify_date = models.DateTimeField(auto_now=True)
class Meta:
db_table = 'remosys_remoshin_doctor_tbl'
### This table is for system administrator.
class RemoshinManager(models.Model):
user = models.OneToOneField(User)
user_type = models.SmallIntegerField(default=3)
manager_id = models.CharField(max_length=16, primary_key=True)
create_date = models.DateTimeField(default=timezone.now)
modify_date = models.DateTimeField(default=timezone.now)
class Meta:
db_table = 'remosys_remoshin_manager_tbl'
【问题讨论】:
-
每个应用程序都有自定义用户模型吗?我不明白这个问题?
-
当你创建一个用户时,是在整个项目中而不仅仅是在应用程序中
-
我不使用自定义用户模型。我使用一对一模型来扩展用户。我必须使用自定义用户模型吗?
-
django 用户属于您的所有应用,而不仅仅是一个。最终用户和管理员用户由您定义。当您创建超级用户时,它将能够管理所有应用程序,而不仅仅是一个。举例说明 App1、App2 和 App3 可能是什么?
-
我添加了模型代码。这个应用程序类似于在线咨询系统。最终用户可以使用智能手机进行咨询服务。医生可以通过 PC 网络浏览器提供服务。我有另一种用户作为系统管理员。他们必须维护系统。
标签: python django python-3.x django-models