我是 django 的新手,我正在关注一些视频讲座。完全按照说明进行操作后,无法添加额外的用户管理界面。我正在附加 mode.py 和 admin.py 进行检查。请帮我
模型.py
class UserProfile(models.Model):
user = models.OneToOneField(User, unique=True)
#Extra values
bio = models.TextField(null=True)
def __unicode__(self):
return '%s Profile' % self.user
def create_profile(sender, instance, created, **kwargs):
if created:
profile, created = UserProfile.objects.get_or_create(user=instance)
from django.db.models.signals import post_save
post_save.connect(create_profile, sender=User )
管理员.py
class UserProfileInLIne(admin.StackedInline):
model = UserProfile
can_delete = False
class UserProfileAdmin(UserAdmin):
inline = (UserProfileInLIne, )
admin.site.unregister(User)
admin.site.register(User, UserProfileAdmin)