Login

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

Author:
dodgyville
Posted:
February 11, 2009
Language:
Python
Version:
1.0
Score:
0 (after 0 ratings)

My problem was that I needed user names with fullstops in them (eg dodgy.ville), but the slugfield on the admin form was rejecting them. This small snippet overrides the validation field on the admin form,

To use it: place it in your admin.py

 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. Template tag - list punctuation for a list of items by shapiromatron 11 months, 2 weeks ago
  2. JSONRequestMiddleware adds a .json() method to your HttpRequests by cdcarter 11 months, 3 weeks ago
  3. Serializer factory with Django Rest Framework by julio 1 year, 6 months ago
  4. Image compression before saving the new model / work with JPG, PNG by Schleidens 1 year, 7 months ago
  5. Help text hyperlinks by sa2812 1 year, 8 months ago

Comments

Please login first before commenting.