Opened 14 years ago

Closed 13 years ago

#9656 closed (duplicate)

Inherit user's password change link doesn't work

Reported by: Maxim Syabro Owned by: nobody
Component: contrib.admin Version: 1.0
Severity: Keywords:
Cc: Triage Stage: Accepted
Has patch: no Needs documentation: no
Needs tests: no Patch needs improvement: no
Easy pickings: no UI/UX: no

Description (last modified by Malcolm Tredinnick)

I've created user:

class WTUser(User):
        authtype = models.IntegerField('Authtype', blank=True, null=True, choices = AUTH_TYPES)
        objects = UserManager()

In Admin site I've clicked on WTUser->create new. Instead of enetering login, password and password confirm I've got a big form with all fields.
Next when I click an link "change password" in WTUser edit form, which links to /admin/westtravel/wtuser/password/ and got

Page not found (404)Request Method:	GET
Request URL:

wt user object with primary key u'password' does not exist.

Change History (9)

comment:1 Changed 14 years ago by Maxim Syabro

Please replace an '[' and '?]' with '' and ''

comment:2 Changed 14 years ago by Malcolm Tredinnick

Description: modified (diff)

Fixed description. If only there was some kind of preview button people could use to check before submitting. Oh, wait ... there is.

comment:3 Changed 13 years ago by adam@…

I've seen exactly the same problem (Django 1.02)

comment:4 Changed 13 years ago by Jacob

milestone: 1.1
Triage Stage: UnreviewedAccepted

comment:5 Changed 13 years ago by Alex Gaynor

This occurs because you didn't inherit the user's ModelAdmin where that view is defined, this should be documented at a minimum.

comment:6 Changed 13 years ago by Jacob

Resolution: wontfix
Status: newclosed

You probably want to subclass django.contrib.auth.admin.UserAdmin.

comment:7 Changed 13 years ago by AdamTwiss

Resolution: wontfix
Status: closedreopened

I keep encountering the same problem as per this original ticket. Subclassing from UserAdmin doesn't itself fix it.

My code is:

class Player( User ):
        # Other stuff snipped
	objects = UserManager()

Using Django 1.1 (or 1.02)

If I just do this, then the change_password link is broken as described. If I then set the admin

class PlayerAdmin( UserAdmin ):
	pass, PlayerAdmin )

Then at this point adding a Player in the admin interface just creates a User when added, and shows an error of: http://localhost:8000/admin/website/player/4/

To get it to work I need to extend to do a minimum of:

from django.contrib.auth.admin import UserAdmin
from django.contrib.auth.forms import UserCreationForm
from django.utils.translation import ugettext, ugettext_lazy as _

class PlayerAddForm( UserCreationForm ):
	class Meta:
		model = Player
		fields = ("username","first_name", "last_name" )  
	def __init__(self, *args, **kwargs):
		return super(PlayerAddForm,self).__init__( *args, **kwargs)

class PlayerAdminForm(forms.ModelForm):
	class Meta:
		model = Player
	password = forms.CharField( help_text=_("Use '[algo]$[salt]$[hexdigest]' or use the <a href=\"password/\">change password form</a>."))

class PlayerAdmin( UserAdmin ):
	form = PlayerAdminForm
	add_form = PlayerAddForm, PlayerAdmin )

The fact that this is undocumented and it's taken me a while to figure it out is to me a bug in itself.

If the 'correct' thing to do now is to extend the Auth.User class (rather than user user_profile), then I also think this should be made easier in some way as it's less than obvious and lacks the djangoesque simplicity.

comment:8 Changed 13 years ago by Adam Nelson

milestone: 1.1

milestone:1.1 is done so moving out.

comment:9 Changed 13 years ago by Russell Keith-Magee

Resolution: duplicate
Status: reopenedclosed

The larger issue here is that people want to use different User models, both in admin and in their own code. We need a way to make this easier. I'm going to close this as a dupe of #3011, since that is the ticket for tracking custom User models.

Note: See TracTickets for help on using tickets.
Back to Top