我的目的是在管理員站點上看到用戶名,電子郵件和電話號碼。Django AdminModel的用戶模型字段
我已經通過擴展用戶模型創建用戶配置:
model.py
from django.db import models
from django.contrib.auth.models import User
class UserProfile(models.Model):
user = models.ForeignKey(User, unique=True)
name = models.CharField(max_length=50, null=True,blank=True)
address = models.CharField(max_length=50, null=True,blank=True)
phone = models.CharField(max_length=20, null=True,blank=True)
country = models.CharField(max_length=20, null=True,blank=True)
state = models.CharField(max_length=20, null=True,blank=True)
zip = models.CharField(max_length=10, null=True,blank=True)
code = models.CharField(max_length=40, null=True)
def user_email(self):
return self.user.email
admin.py
from myApp.models import UserProfile
from django.contrib import admin
class UserProfileAdmin(admin.ModelAdmin):
fields = ('name','phone',)
list_display = ('name','user_email',)
admin.site.register(UserProfile, UserProfileAdmin)
等它的工作list_display,我只能看到我選擇的列,但是當我嘗試去管理站點時將'user_email'(fields =('name','user_email','phone',))添加到字段中:
'UserProfileAdmin.fields'引用表單中缺少的字段'user_email'。
我正要回答同樣的事情,這裏是2010年的一篇文章(保佑谷歌):http://blog.timc3.com/2010/02/18/extending-djangos-user-admin/ – 2011-06-01 07:00:55
好的,謝謝所有的答案,但這不是我想要做的。我不試圖替換Django adminUser我試圖離開Django用戶模型是這樣的,我想在我的項目中有另一種用戶類型,在未來可能會登錄到系統,但現在我只想採取細節併發給他電子郵件,通訊等。 – user625135 2011-06-02 11:43:48