Reputation: 31252
This is how my admin look now.
when I click the Add User
on the right side, I get a form
which does not have first name, Last name and Email address fields. but only username and password
, as below
I am using Django-registration
to register new users. I have attached UserProfile
to User
. The UserProfile
has only two fields, Photo
and isPublic
?
how can I get my admin
to include all fields (such as First name, last name, email address) in the admin form
.
EDIT: Traceback here
ValueError at /admin/auth/user/add/
too many values to unpack
Request Method: GET
Request URL: http://127.0.0.1:8000/admin/auth/user/add/
Django Version: 1.6.2
Exception Type: ValueError
Exception Value:
too many values to unpack
Exception Location: /Users/Documents/virtualenvs/django/django/lib/python2.7/site-packages/django/contrib/admin/util.py in flatten_fieldsets, line 90
Python Executable: /Users/Documents/virtualenvs/django/django/bin/python
Python Version:
Upvotes: 1
Views: 552
Reputation: 6735
The UserAdmin
of django.contrib.auth
specifically overrides the form used for adding a new User
. It differs from the change form because it needs to ask twice for the password.
If you look at the source code for UserAdmin
, you'll see that you can set your own creation form by setting the add_form
option. It should inherit from the original UserCreationForm
to keep the password setting logic. For example:
class MyUserCreationForm(UserCreationForm):
class Meta(UserCreationForm.Meta):
fields = ('username', 'first_name', 'last_name') # etc...
class MyUserAdmin(UserAdmin):
add_form = MyUserCreationForm
add_fieldsets = UserAdmin.add_fieldsets + ("More fields", {"fields": ('first_name', 'last_name')},)
# don't forget to register your custom admin class
admin.site.unregister(UserAdmin)
admin.site.register(User, MyUserAdmin)
Upvotes: 1