Replace slugfield validation for User username in Admin form with a CharField

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
from django.contrib.auth.models import User
from django.contrib.auth.admin import UserAdmin
from django.forms import ModelForm
from django import forms

class EzyUserAdminForm(ModelForm):
    """ Override the admin page for user to allow non-slug login names """
    username = forms.CharField()
    class Meta:
         model = User 

class EzyUserAdmin(UserAdmin):
    form = EzyUserAdminForm

admin.site.unregister(User) #deregister the old user admin
admin.site.register(User, EzyUserAdmin)  #register our new form

More like this

  1. notify admin what fields have changed in form submission by pjv 3 years, 4 months ago
  2. Password Validation - Require Letters and Numbers - no regex by watchedman 2 years, 7 months ago
  3. clean validation for dynamic form fields by leveillej 3 years, 11 months ago
  4. Validate request params without custom form by xiaoym 1 year ago
  5. isUnique validator for newforms by clamothe 5 years, 8 months ago

Comments

(Forgotten your password?)