Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse files

Fixed #7932 -- Made it easier to use a custom User model with the adm…

…in. Added add_form attribute to UserAdmin and removed hard-coded dependancies to User. Thanks ElliottM for the patch.

git-svn-id: http://code.djangoproject.com/svn/django/trunk@8280 bcc190cf-cafb-0310-a4f2-bffc1f526a37
  • Loading branch information...
commit baac791c4b3482b7d5a4e8506bf03a61d411e563 1 parent 02cc591
Brian Rosner brosner authored
Showing with 6 additions and 6 deletions.
  1. +6 −6 django/contrib/auth/admin.py
12 django/contrib/auth/admin.py
View
@@ -4,6 +4,7 @@
from django.shortcuts import render_to_response
from django.http import HttpResponseRedirect
from django.utils.translation import ugettext, ugettext_lazy as _
+from django.contrib.auth.forms import UserCreationForm
from django.contrib import admin
class GroupAdmin(admin.ModelAdmin):
@@ -19,6 +20,7 @@ class UserAdmin(admin.ModelAdmin):
(_('Important dates'), {'fields': ('last_login', 'date_joined')}),
(_('Groups'), {'fields': ('groups',)}),
)
+ add_form = UserCreationForm
list_display = ('username', 'email', 'first_name', 'last_name', 'is_staff')
list_filter = ('is_staff', 'is_superuser')
search_fields = ('username', 'first_name', 'last_name', 'email')
@@ -26,12 +28,10 @@ class UserAdmin(admin.ModelAdmin):
filter_horizontal = ('user_permissions',)
def add_view(self, request):
- # avoid a circular import. see #6718.
- from django.contrib.auth.forms import UserCreationForm
if not self.has_change_permission(request):
raise PermissionDenied
if request.method == 'POST':
- form = UserCreationForm(request.POST)
+ form = self.add_form(request.POST)
if form.is_valid():
new_user = form.save()
msg = _('The %(name)s "%(obj)s" was added successfully.') % {'name': 'user', 'obj': new_user}
@@ -42,7 +42,7 @@ def add_view(self, request):
request.user.message_set.create(message=msg + ' ' + ugettext("You may edit it again below."))
return HttpResponseRedirect('../%s/' % new_user.id)
else:
- form = UserCreationForm()
+ form = self.add_form()
return render_to_response('admin/auth/user/add_form.html', {
'title': _('Add user'),
'form': form,
@@ -55,9 +55,9 @@ def add_view(self, request):
'has_file_field': False,
'has_absolute_url': False,
'auto_populated_fields': (),
- 'opts': User._meta,
+ 'opts': self.model._meta,
'save_as': False,
- 'username_help_text': User._meta.get_field('username').help_text,
+ 'username_help_text': self.model._meta.get_field('username').help_text,
'root_path': self.admin_site.root_path,
}, context_instance=template.RequestContext(request))
Please sign in to comment.
Something went wrong with that request. Please try again.