Opened 7 years ago
Closed 7 years ago
#29270 closed Bug (fixed)
KeyError if using 'password' as readonly_fields in UserAdmin
Description ¶
If 'password' is added as readonly_field in UserAdmin, a KeyError is thrown, as the UserChangeForm expects a password field to exists.
from django.contrib.auth.admin import UserAdmin as BaseUserAdmin class UserAdmin(BaseUserAdmin): readonly_fields = ['username', 'password'] admin.site.register(User, UserAdmin)
class UserChangeForm(forms.ModelForm): # ... def __init__(self, *args, **kwargs): super().__init__(*args, **kwargs) self.fields['password'].help_text = self.fields['password'].help_text.format('../password/') # ...
Change History (5)
comment:1 by , 7 years ago
comment:2 by , 7 years ago
Triage Stage: | Unreviewed → Accepted |
---|
.keys()
isn't needed, otherwise the fix looks reasonable. A test goes in tests/auth_tests/test_forms.py
-- can you offer a pull request?
comment:3 by , 7 years ago
Easy pickings: | set |
---|---|
Owner: | changed from | to
Status: | new → assigned |
comment:4 by , 7 years ago
Ok, I tried to make a pull request
https://github.com/django/django/pull/9833
Note:
See TracTickets
for help on using tickets.
This should fix the issue for now: