Hi all,
I'm running Django 1.7 and Python 3.4. I'm trying to make the username
field of my custom model to be read-only. I think this is usually set in
the form. Below is what I currently have in my *forms.py*
class AuthUserChangeForm(UserChangeForm):
"""
A form for updating users. Includes all the fields on the user, but
replaces the password field with admin's password hash display field.
"""
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>""")
class Meta:
model = AuthUser
fields = ('username', 'email', 'password', 'is_active', 'is_staff',
'is_superuser', 'user_permissions')
widgets = {
'username': TextInput( attrs={'readonly':'readonly'} ),
'email': TextInput(),
}
def clean_username(self):
# Regardless of what the user provides, reset field to initial value
# Not appropriate to change usernames once set.
return self.initial["username"]
def clean_password(self):
# Regardless of what the user provides, return the initial value.
# This is done here, rather than on the field, because the field
does
# not have access to the initial value
return self.initial["password"]
What I'm I missing here?
--
You received this message because you are subscribed to the Google Groups
"Django users" group.
To unsubscribe from this group and stop receiving emails from it, send an email
to [email protected].
To post to this group, send email to [email protected].
Visit this group at http://groups.google.com/group/django-users.
To view this discussion on the web visit
https://groups.google.com/d/msgid/django-users/CAEAUGdVbcmJcLp-j292v8c%2BNA9PS7z%3DN5kAKST84hC9jHfb0cQ%40mail.gmail.com.
For more options, visit https://groups.google.com/d/optout.