我正在尝试扩展 Django 用户模型以包含另一个字段。如文档中所述,我对该字段进行了如下扩展:
class Employee(models.Model):
# This field is required.
user = models.OneToOneField(User)
manager_id = models.ForeignKey(User, related_name='employees')
我希望 manager_id 能够自我引用并与用户相关(而不是定义新的经理表),并且只需在一般用户页面中显示新字段。为此,按照文档中的说明,我还添加了以下内容:
class EmployeeInline(admin.StackedInline):
model = Employee
can_delete = False
verbose_name_plural = 'employee'
# Define a new User admin
class UserAdmin(UserAdmin):
inlines = (EmployeeInline, )
# Re-register UserAdmin
admin.site.unregister(User)
admin.site.register(User, UserAdmin)
但是,我收到以下异常:
<class 'dhtmlScheduler.models.Employee'> has more than 1 ForeignKey to <class 'django.contrib.auth.models.User'>
任何人都可以提供任何指示吗?