Opened 16 years ago

Closed 15 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:	http://127.0.0.1:8000/admin/westtravel/wtuser/password/


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

Change History (9)

comment:1 by Maxim Syabro, 16 years ago

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

comment:2 by Malcolm Tredinnick, 16 years ago

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 by adam@…, 16 years ago

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

comment:4 by Jacob, 16 years ago

milestone: 1.1
Triage Stage: UnreviewedAccepted

comment:5 by Alex Gaynor, 16 years ago

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 by Jacob, 16 years ago

Resolution: wontfix
Status: newclosed

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

comment:7 by AdamTwiss, 15 years ago

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:
models.py:

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

admin.py:

class PlayerAdmin( UserAdmin ):
	pass
admin.site.register(Player, 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 admin.py 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
	
admin.site.register(Player, 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 by Adam Nelson, 15 years ago

milestone: 1.1

milestone:1.1 is done so moving out.

comment:9 by Russell Keith-Magee, 15 years ago

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