Django 1.10.2
研究用户模型的自定义。
尝试关注文档https://docs.djangoproject.com/en/1.10/topics/auth/customizing/#extending-the-existing-user-model
我希望存储该部门并将其显示在管理员中。 问题是部门没有出现。
我使用了fieldsets和list_display,但失败了。
你能帮我理解如何在管理员中展示部门吗?
admin.py
from django.contrib.auth.models import User
from django.db import models
from django.contrib import admin
from django.contrib.auth.admin import UserAdmin as BaseUserAdmin
from django.contrib.auth.models import User
class Employee(models.Model):
user = models.OneToOneField(User, on_delete=models.CASCADE)
department = models.CharField(max_length=100)
# Define an inline admin descriptor for Employee model
# which acts a bit like a singleton
class EmployeeInline(admin.StackedInline):
model = Employee
can_delete = False
verbose_name_plural = 'employee'
# Define a new User admin
class UserAdmin(BaseUserAdmin):
inlines = (EmployeeInline, )
# Re-register UserAdmin
admin.site.unregister(User)
admin.site.register(User, UserAdmin)