我有一个模型,我希望在管理员网站上显示。
models.py:
class UserDetails(models.Model):
user = models.OneToOneField(User, on_delete=models.CASCADE, related_name='userdetails')
address = models.CharField(max_length=50, default='Not set')
def __unicode__(self):
return u' %s %s ' % (self.user, self.address)
admin.py:
from django.contrib import admin
from django.contrib.auth.models import User
from django.contrib.auth.admin import UserAdmin
from index.models import User, UserDetails
class UserDetailsAdmin(admin.ModelAdmin):
fields = ("address",)
admin.site.unregister(User)
admin.site.register(User, UserDetailsAdmin)
我收到错误:
FieldError:为User指定的未知字段(地址)。检查字段/字段集/排除类UserDetailsAdmin的属性。
出了什么问题?
答案 0 :(得分:4)
这样做get details of your model attribute
:
class UserDetailsAdmin(admin.ModelAdmin):
list_display = ('address', 'user')
admin.site.register(UserDetails, UserDetailsAdmin)
list_display
控制fields
displayed
admin
Sub CopyPaste()
time1 = Timer
Application.ScreenUpdating = False
Application.Calculation = xlCalculationManual
*your code here*
Application.ScreenUpdating = True
Application.Calculation = xlCalculationAutomatic
End Sub
答案 1 :(得分:2)
在 admin.py
中更改
admin.site.register(User, UserDetailsAdmin)
admin.site.unregister(User)
到
admin.site.register(UserDetails, UserDetailsAdmin)
admin.site.register(User)