Skip to content

Instantly share code, notes, and snippets.

@8area8
Created August 5, 2021 09:08
Show Gist options
  • Save 8area8/634d9c168b88291b3fd2b5cf22d49310 to your computer and use it in GitHub Desktop.
Save 8area8/634d9c168b88291b3fd2b5cf22d49310 to your computer and use it in GitHub Desktop.
Django - User form for admin panel (not safe)
"""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