英文:
How to properly extend user model in Django
问题
我正在开发一个Django员工管理系统,我希望员工的个人信息数据能够与用于注册和登录的用户对象在同一表中。
我尝试将用户模型添加为员工表中的OneToOneField,但我不喜欢用户需要先注册,然后单独填写员工表单。
我希望用户在创建帐户的同时能够创建他们的个人信息。
英文:
I am working on a Django employee management system, I want the employee bio data on the same table as the user object used for registration and login
I tried adding the user model as a OnetoOneField on the employee table, but I don’t like having to register the user and then fill the employee form separately.
I want the users to be able to create their bio data while creating an account
答案1
得分: 1
你可以继承AbstractBaseUser模型并覆盖它(在其中添加额外字段),然后你可以完全按照你的要求进行操作,即:
class User(AbstractBaseUser):
date_joined = models.DateTimeField(auto_now_add=True)
is_active = models.BooleanField(default=True)
# 其他字段
英文:
you can inherit AbstractBaseUser model and override it(add additionally fields in it) and you can do what exactly you want i.e
class User(AbstractBaseUser):
date_joined = models.DateTimeField(auto_now_add=True)
is_active = models.BooleanField(default=True)
---> rest of fields <------
答案2
得分: 0
数据库设计可能因人而异。在这种情况下,我会继承AbstractBaseUser
,并将所有内容保存在该表中。
英文:
database design may always vary depending on people. In such a case, I will inherit abstractbaseuser and keep everything in that table.
通过集体智慧和协作来改善编程学习和解决问题的方式。致力于成为全球开发者共同参与的知识库,让每个人都能够通过互相帮助和分享经验来进步。
评论