Code

Opened 5 years ago

Closed 4 years ago

#9656 closed (duplicate)

Inherit user's password change link doesn't work

Reported by: 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: UI/UX:

Description (last modified by mtredinnick)

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.

Attachments (0)

Change History (9)

comment:1 Changed 5 years ago by syabro

  • Needs documentation unset
  • Needs tests unset
  • Patch needs improvement unset

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

comment:2 Changed 5 years ago by mtredinnick

  • 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 5 years ago by adam@…

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

comment:4 Changed 5 years ago by jacob

  • milestone set to 1.1
  • Triage Stage changed from Unreviewed to Accepted

comment:5 Changed 5 years ago by Alex

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 5 years ago by jacob

  • Resolution set to wontfix
  • Status changed from new to closed

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

comment:7 Changed 5 years ago by AdamTwiss

  • Resolution wontfix deleted
  • Status changed from closed to reopened

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 Changed 4 years ago by adamnelson

  • milestone 1.1 deleted

milestone:1.1 is done so moving out.

comment:9 Changed 4 years ago by russellm

  • Resolution set to duplicate
  • Status changed from reopened to closed

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.

Add Comment

Modify Ticket

Change Properties
<Author field>
Action
as closed
as The resolution will be set. Next status will be 'closed'
The resolution will be deleted. Next status will be 'new'
Author


E-mail address and user name can be saved in the Preferences.

 
Note: See TracTickets for help on using tickets.