Skip to content
This repository

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse code

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 authored August 10, 2008

Showing 1 changed file with 6 additions and 6 deletions. Show diff stats Hide diff stats

  1. 12  django/contrib/auth/admin.py
12  django/contrib/auth/admin.py
@@ -4,6 +4,7 @@
4 4
 from django.shortcuts import render_to_response
5 5
 from django.http import HttpResponseRedirect
6 6
 from django.utils.translation import ugettext, ugettext_lazy as _
  7
+from django.contrib.auth.forms import UserCreationForm
7 8
 from django.contrib import admin
8 9
 
9 10
 class GroupAdmin(admin.ModelAdmin):
@@ -19,6 +20,7 @@ class UserAdmin(admin.ModelAdmin):
19 20
         (_('Important dates'), {'fields': ('last_login', 'date_joined')}),
20 21
         (_('Groups'), {'fields': ('groups',)}),
21 22
     )
  23
+    add_form = UserCreationForm
22 24
     list_display = ('username', 'email', 'first_name', 'last_name', 'is_staff')
23 25
     list_filter = ('is_staff', 'is_superuser')
24 26
     search_fields = ('username', 'first_name', 'last_name', 'email')
@@ -26,12 +28,10 @@ class UserAdmin(admin.ModelAdmin):
26 28
     filter_horizontal = ('user_permissions',)
27 29
 
28 30
     def add_view(self, request):
29  
-        # avoid a circular import. see #6718.
30  
-        from django.contrib.auth.forms import UserCreationForm
31 31
         if not self.has_change_permission(request):
32 32
             raise PermissionDenied
33 33
         if request.method == 'POST':
34  
-            form = UserCreationForm(request.POST)
  34
+            form = self.add_form(request.POST)
35 35
             if form.is_valid():
36 36
                 new_user = form.save()
37 37
                 msg = _('The %(name)s "%(obj)s" was added successfully.') % {'name': 'user', 'obj': new_user}
@@ -42,7 +42,7 @@ def add_view(self, request):
42 42
                     request.user.message_set.create(message=msg + ' ' + ugettext("You may edit it again below."))
43 43
                     return HttpResponseRedirect('../%s/' % new_user.id)
44 44
         else:
45  
-            form = UserCreationForm()
  45
+            form = self.add_form()
46 46
         return render_to_response('admin/auth/user/add_form.html', {
47 47
             'title': _('Add user'),
48 48
             'form': form,
@@ -55,9 +55,9 @@ def add_view(self, request):
55 55
             'has_file_field': False,
56 56
             'has_absolute_url': False,
57 57
             'auto_populated_fields': (),
58  
-            'opts': User._meta,
  58
+            'opts': self.model._meta,
59 59
             'save_as': False,
60  
-            'username_help_text': User._meta.get_field('username').help_text,
  60
+            'username_help_text': self.model._meta.get_field('username').help_text,
61 61
             'root_path': self.admin_site.root_path,
62 62
         }, context_instance=template.RequestContext(request))
63 63
 

0 notes on commit baac791

Please sign in to comment.
Something went wrong with that request. Please try again.