我不得不延長UserCreationForm和UserChangeForm:
admin.py
from django.contrib.auth.models import User
from django.contrib.auth.forms import UserCreationForm, UserChangeForm
from django.contrib.auth.admin import UserAdmin
from django.contrib import admin
from django import forms
class MyUser1CreationForm(UserCreationForm):
myuser1_field = forms.CharField()
class Meta:
model = User
fields = ("username", "myuser1_field", "password1", "password2")
class MyUser1ChangeForm(UserChangeForm):
myuser1_field = forms.CharField()
class Meta:
model = User
class MyUser1Admin(UserAdmin):
form = MyUser1ChangeForm
add_form = MyUser1CreationForm
fieldsets = (
(None, {'fields': ('username', 'password')}),
(_('Personal info'), {'fields': ('myuser1_field', 'first_name', 'last_name', 'email')}),
(_('Permissions'), {'fields': ('is_active', 'is_staff', 'is_superuser',
'groups', 'user_permissions')}),
(_('Important dates'), {'fields': ('last_login', 'date_joined')}),
)
add_fieldsets = (
(None, {
'classes': ('wide',),
'fields': ('username', 'myuser1_field', 'password1', 'password2')}
),
)
admin.site.register(MyUser1, MyUser1Admin)
來源
2012-12-12 14:07:16
jul
說'myuser1_field'是在自定義用戶模型的字段。有沒有一種方法來創建字段使用模型的定義 – surfer190