Created
September 26, 2014 09:09
-
-
Save yuvadm/c5afa16b07747b113808 to your computer and use it in GitHub Desktop.
Django 1.5+ username field length monkey patch
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# https://stackoverflow.com/questions/25136282/what-is-the-right-way-to-extend-the-username-field-length-in-django-1-5 | |
from django.contrib.auth.forms import UserCreationForm | |
from django.contrib.auth.models import AbstractUser | |
class MyUser(AbstractUser): | |
pass | |
USERNAME_LENGTH = 50 | |
MyUser._meta.get_field('username').max_length = USERNAME_LENGTH | |
MyUser._meta.get_field('username').validators[0].limit_value = USERNAME_LENGTH | |
MyUser._meta.get_field('username').validators[1].limit_value = USERNAME_LENGTH | |
UserCreationForm.base_fields['username'].max_length = USERNAME_LENGTH | |
UserCreationForm.base_fields['username'].validators[0].limit_value = USERNAME_LENGTH |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment