Skip to content
Snippets Groups Projects
forms.py 689 B
Newer Older
  • Learn to ignore specific revisions
  • from django import forms
    
    from wagtail.wagtailusers.forms import UserEditForm, UserCreationForm
    
    
    Dan Braghis's avatar
    Dan Braghis committed
    
    
    class CustomUserAdminFormBase():
    
        def __init__(self, *args, **kwargs):
    
    Dan Braghis's avatar
    Dan Braghis committed
            super().__init__(*args, **kwargs)
    
    
            # HACK: Wagtail admin doesn't work with custom User models that do not have first/last name.
    
    Dan Braghis's avatar
    Dan Braghis committed
            self.fields['first_name'].widget = forms.HiddenInput(attrs={'value': f"Not used - see full_name"})
            self.fields['last_name'].widget = forms.HiddenInput(attrs={'value': f"Not used - see full_name"})
    
    Dan Braghis's avatar
    Dan Braghis committed
    
    
    class CustomUserEditForm(CustomUserAdminFormBase, UserEditForm):
        pass
    
    Dan Braghis's avatar
    Dan Braghis committed
    
    
    class CustomUserCreationForm(CustomUserAdminFormBase, UserCreationForm):
        pass