Hello,
In my project I need to set some certain fields to ltr
direction because the whole project is in rtl
direction so this is what I do:
class CustomUserCreationForm(UserCreationForm):
def __init__(self, *args, **kwargs):
super().__init__(*args, **kwargs)
self.fields['email'].widget.attrs.update({'dir': 'ltr'})
self.fields['password1'].widget.attrs.update({'dir': 'ltr'})
self.fields['password2'].widget.attrs.update({'dir': 'ltr'})
class CustomUserChangeForm(UserChangeForm):
def __init__(self, *args, **kwargs):
super().__init__(*args, **kwargs)
self.fields['email'].widget.attrs.update({'dir': 'ltr'})
class CustomAdminPasswordChangeForm(AdminPasswordChangeForm):
def __init__(self, *args, **kwargs):
super().__init__(*args, **kwargs)
self.fields['password1'].widget.attrs.update({'dir': 'ltr'})
self.fields['password2'].widget.attrs.update({'dir': 'ltr'})
class CustomPasswordChangeForm(PasswordChangeForm):
def __init__(self, *args, **kwargs):
super().__init__(*args, **kwargs)
self.fields['old_password'].widget.attrs.update({'dir': 'ltr'})
self.fields['new_password1'].widget.attrs.update({'dir': 'ltr'})
self.fields['new_password2'].widget.attrs.update({'dir': 'ltr'})
And then:
class UserAdmin(UserAdmin):
add_form = CustomUserCreationForm
form = CustomUserChangeForm
change_password_form = CustomAdminPasswordChangeForm
The above 3 forms work as expected, however the CustomAdminPasswordChangeForm
is for when the Superuser
is changing the password. This form does not ask for Old Password.
But when a Staff
logs into Admin site, another form is used to change the password which asks for Old Password too.
I have customized that form too (CustomPasswordChangeForm
) but I can’t find how to set it in my UserAdmin
class?