- 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
- get_object_or_none by azwdevops 3 months, 2 weeks ago
- Mask sensitive data from logger by agusmakmun 5 months, 1 week ago
- Template tag - list punctuation for a list of items by shapiromatron 1 year, 7 months ago
- JSONRequestMiddleware adds a .json() method to your HttpRequests by cdcarter 1 year, 7 months ago
- Serializer factory with Django Rest Framework by julio 2 years, 2 months ago
Comments
Please login first before commenting.