Friday, November 30, 2012

Re: django1.5 subclass AbstractUser, How to get a password-(re)set field in admin

Hi Russ, 

Thanks that did solve the problem I was having. 

--
Regards,
Bruce


On Fri, Nov 30, 2012 at 9:32 PM, Russell Keith-Magee <russell@keith-magee.com> wrote:
Hi Bruce,

Update your Django checkout. This problem was fixed in 0fc5878c.

Yours,
Russ Magee %-)


On Fri, Nov 30, 2012 at 2:07 PM, Detectedstealth <bruce.wade@gmail.com> wrote:
Hi Russel,


password = ReadOnlyPasswordHashField(label=_("Password"),

        help_text=_("Raw passwords are not stored, so there is no way to see "

                    "this user's password, but you can change the password "

                    "using <a href=\"password/\">this form</a>."), widget=ReadOnlyPasswordHashWidget()) 

From what I seen in django/contrib/auth/forms UserChangeForm this gives me the change password URL however I get the error: 'CustUser' object has no attribute 'username' looking at the error line 136

/Library/Python/2.7/site-packages/django/contrib/auth/admin.py in user_change_password

  1.             'title': _('Change password: %s') % escape(user.username), 
It looks like this is either a bug or doesn't work with a custom user as planed as it looks for a username even though in the example you set the email to username field with: USERNAME_FIELD = 'email'

Am I missing something?

Regards,
Bruce

On Saturday, November 3, 2012 4:09:09 PM UTC-7, Russell Keith-Magee wrote:

On Sat, Nov 3, 2012 at 11:15 PM, Michael Muster <michael...@googlemail.com> wrote:
Hi again,

I have a subclass from AbstractUser

1 from django.contrib.auth.models import AbstractUser
2 from django.conf import settings
3
4 class cpUser(AbstractUser):
5     twitter = models.CharField(max_length=100)
6     def __unicode__(self):
7         return self.username

and
AUTH_USER_MODEL = 'account.cpUser'
in my settings.py set.

How do i get a password field to set and reset
a password in my admin app?
Adding the password field to admin.py does obviously not
work as it enters plain text and not the hashed password.

1 from django.contrib import admin
2 class cpUserAdmin(admin.ModelAdmin):
3    fields = ['twitter','username', 'first_name', 'last_name', 'password',]
4                                                                ~~~~~~~~
5 admin.site.register(cpUser, cpUserAdmin)


Do i have to set a passwort field to the models.py or
can i geht that from the models which i "abstracted" from
(as done with username, first_name, last_name...)

You need to follow the instructions that are in the documentation.


The key is that you can't just subclass admin.ModelAdmin -- you need to subclass the existing Django admin class for Users (django.contrib.auth.admin.UserAdmin) - that base class is what provides all the special password handling etc for User models.

Yours,
Russ Magee %-) 

--
You received this message because you are subscribed to the Google Groups "Django users" group.
To view this discussion on the web visit https://groups.google.com/d/msg/django-users/-/sRmpO1m1Ng0J.
To post to this group, send email to django-users@googlegroups.com.
To unsubscribe from this group, send email to django-users+unsubscribe@googlegroups.com.
For more options, visit this group at http://groups.google.com/group/django-users?hl=en.

--
You received this message because you are subscribed to the Google Groups "Django users" group.
To post to this group, send email to django-users@googlegroups.com.
To unsubscribe from this group, send email to django-users+unsubscribe@googlegroups.com.
For more options, visit this group at http://groups.google.com/group/django-users?hl=en.



--
--
Regards,
Bruce Wade
http://ca.linkedin.com/in/brucelwade
http://www.wadecybertech.com

--
You received this message because you are subscribed to the Google Groups "Django users" group.
To post to this group, send email to django-users@googlegroups.com.
To unsubscribe from this group, send email to django-users+unsubscribe@googlegroups.com.
For more options, visit this group at http://groups.google.com/group/django-users?hl=en.

No comments:

Post a Comment