我现在很困惑。我在一个项目中有 3 个应用程序。
App1 : 从最终用户使用(基于 WebView 的应用程序)
App2 : 从服务提供商(网络服务)使用
App3 : 从系统管理员处使用。
我想为每个应用程序使用 django 身份验证系统。我可以制作 django 项目来验证 App1 的用户。但是,如何同时使用App2和App3的认证系统。
当我运行 python manage.py createsuperuser
命令时,django 生成 App1 的 super 用户。如何使用此命令创建 App2 和 App3?
有人知道吗?请帮我。
模型.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'
最佳答案
您可以使用以下方法从命令行创建用户。但是无论何时创建用户,它都是为整个项目而不是为一个应用程序创建的。
user@hostname$ python3 -m django shell
>>> import django.contrib.auth
>>> User = django.contrib.auth.get_user_model()
>>> user = User.objects.create_user('username', password='userpassword')
>>> user.is_superuser = False
>>> user.is_staff = False
>>> user.save()
关于python - 在 Django 中从命令行创建用户,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/46010177/