我在我的用户模型中添加了一个名为 extra 的字段,如下所示:-
class ExtendedUser(models.Model):
user = models.OneToOneField(User)
extra = models.CharField(max_length=30, null=True)
# when a user is created, make sure an ExtendedUser is created too
def create_extended_user(sender, instance, created, *args, **kwargs):
if created:
extended_user = ExtendedUser(user=instance)
extended_user.save()
post_save.connect(create_extended_user, sender=User)
在我的 admin.py 中,我尝试确保在编辑用户时可以编辑这个额外的字段:-
class ExtendedUserInline(admin.TabularInline):
model = ExtendedUser
fk_name = 'user'
max_num = 1
class ExtendedUserAdmin(UserAdmin):
inlines = [ExtendedUserInline]
admin.site.unregister(User)
admin.site.register(User, ExtendedUserAdmin)
但是,我在用户的管理页面中看不到额外的字段。
我做错了什么?