[英]Extending Django's User model
I have been dealing for a while with Django's authentication system and I just cannot understand why I have to go through this process Django doc ! 我使用Django的身份验证系统已经有一段时间了,我只是不明白为什么我必须经历这个过程Django doc ! : :
from django.contrib.auth.models import User
class Employee(models.Model):
user = models.OneToOneField(User)
department = models.CharField(max_length=100)
... rather than simply extending the "User" class like this: ...而不是像这样简单地扩展“ User”类:
class Employee(User):
....
... and re-using all the code contained within. ...并重新使用其中包含的所有代码。 I have taken a look at articles like: b-list.org ! 我看过类似的文章: b-list.org ! , and I understand that the problem may be related with the automatic Django database management. ,并且我知道该问题可能与Django自动数据库管理有关。
Is there a way in which I can automatically extend the User model without having to create an additional table in the database, so that Django modifies the current database table for me? 有没有一种方法可以自动扩展User模型而无需在数据库中创建其他表,以便Django为我修改当前数据库表?
I tend to obey the fellas of the django 我倾向于服从django的小伙子们
https://docs.djangoproject.com/en/1.5/topics/auth/customizing/#extending-the-existing-user-model https://docs.djangoproject.com/zh-CN/1.5/topics/auth/customizing/#extending-the-existing-user-model
Because only abstract models don't create tables in django and built-in user model is not 因为只有抽象模型无法在Django中创建表,而内置用户模型却无法
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.