Permalink
Browse files

Don't assume USERNAME_FIELD == 'user' in UserAdmin.

Never assume that a user object has a field named `username`, use
`USERNAME_FIELD` instead.

fixes #19077
  • Loading branch information...
gavinwahl committed Oct 5, 2012
1 parent ab696e3 commit af667c2283e4e8a1fb8673ca7d2b9850b8f92df3
Showing with 3 additions and 2 deletions.
  1. +3 −2 django/contrib/auth/admin.py
@@ -106,9 +106,10 @@ def add_view(self, request, form_url='', extra_context=None):
raise PermissionDenied
if extra_context is None:
extra_context = {}
+ username_field = self.model._meta.get_field(getattr(self.model, 'USERNAME_FIELD', 'username'))
defaults = {
'auto_populated_fields': (),
- 'username_help_text': self.model._meta.get_field('username').help_text,
+ 'username_help_text': username_field.help_text,
}
extra_context.update(defaults)
return super(UserAdmin, self).add_view(request, form_url,
@@ -133,7 +134,7 @@ def user_change_password(self, request, id, form_url=''):
adminForm = admin.helpers.AdminForm(form, fieldsets, {})
context = {
- 'title': _('Change password: %s') % escape(user.username),
+ 'title': _('Change password: %s') % escape(str(user)),
'adminForm': adminForm,
'form_url': form_url,
'form': form,

0 comments on commit af667c2

Please sign in to comment.