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