Created
August 5, 2021 09:08
-
-
Save 8area8/634d9c168b88291b3fd2b5cf22d49310 to your computer and use it in GitHub Desktop.
Django - User form for admin panel (not safe)
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
"""User forms.""" | |
from django import forms | |
from django.contrib.auth import get_user_model | |
from django.contrib.auth.forms import UserCreationForm | |
from django.utils.translation import gettext_lazy as _ | |
User = get_user_model() | |
class UserAdminForm(UserCreationForm): | |
"""Admin panel form : no password validations.""" | |
password1 = forms.CharField( | |
label=_("Password"), | |
strip=False, | |
widget=forms.PasswordInput(attrs={"autocomplete": "new-password"}), | |
help_text=_("No password restrictions here. ;)"), | |
) | |
def _post_clean(self): | |
"""Hack : avoids validation of UserCreationForm passwords.""" | |
return forms.ModelForm._post_clean(self) # type: ignore |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment