From d5b573d872bbe0d5825efaee2d41cb3cdc75417b Mon Sep 17 00:00:00 2001 From: Thom Wiggers Date: Sun, 22 Jan 2017 15:45:42 +0100 Subject: [PATCH] Fixed #26993 -- Increased User.last_name max_length to 150 characters. --- AUTHORS | 1 + .../0009_alter_user_last_name_max_length.py | 16 +++++++++++ django/contrib/auth/models.py | 2 +- docs/ref/contrib/auth.txt | 6 ++++- docs/releases/2.0.txt | 27 +++++++++++++++++++ 5 files changed, 50 insertions(+), 2 deletions(-) create mode 100644 django/contrib/auth/migrations/0009_alter_user_last_name_max_length.py diff --git a/AUTHORS b/AUTHORS index dbc414f5a37..c0b3778afa4 100644 --- a/AUTHORS +++ b/AUTHORS @@ -738,6 +738,7 @@ answer newbie questions, and generally made Django that much better: thebjorn Thejaswi Puthraya Thijs van Dien + Thom Wiggers Thomas Chaumeny Thomas Güttler Thomas Kerpe diff --git a/django/contrib/auth/migrations/0009_alter_user_last_name_max_length.py b/django/contrib/auth/migrations/0009_alter_user_last_name_max_length.py new file mode 100644 index 00000000000..b217359e485 --- /dev/null +++ b/django/contrib/auth/migrations/0009_alter_user_last_name_max_length.py @@ -0,0 +1,16 @@ +from django.db import migrations, models + + +class Migration(migrations.Migration): + + dependencies = [ + ('auth', '0008_alter_user_username_max_length'), + ] + + operations = [ + migrations.AlterField( + model_name='user', + name='last_name', + field=models.CharField(blank=True, max_length=150, verbose_name='last name'), + ), + ] diff --git a/django/contrib/auth/models.py b/django/contrib/auth/models.py index 7476a695178..7da65666b1a 100644 --- a/django/contrib/auth/models.py +++ b/django/contrib/auth/models.py @@ -311,7 +311,7 @@ class AbstractUser(AbstractBaseUser, PermissionsMixin): }, ) first_name = models.CharField(_('first name'), max_length=30, blank=True) - last_name = models.CharField(_('last name'), max_length=30, blank=True) + last_name = models.CharField(_('last name'), max_length=150, blank=True) email = models.EmailField(_('email address'), blank=True) is_staff = models.BooleanField( _('staff status'), diff --git a/docs/ref/contrib/auth.txt b/docs/ref/contrib/auth.txt index a2692306437..265dc535790 100644 --- a/docs/ref/contrib/auth.txt +++ b/docs/ref/contrib/auth.txt @@ -47,7 +47,11 @@ Fields .. attribute:: last_name - Optional. 30 characters or fewer. + Optional. 150 characters or fewer. + + .. versionchanged:: 2.0 + + The ``max_length`` increased from 30 to 150 characters. .. attribute:: email diff --git a/docs/releases/2.0.txt b/docs/releases/2.0.txt index 2ef6ba9be10..7cb9b5da73d 100644 --- a/docs/releases/2.0.txt +++ b/docs/releases/2.0.txt @@ -217,6 +217,33 @@ The end of upstream support for Oracle 11.2 is Dec. 2020. Django 1.11 will be supported until April 2020 which almost reaches this date. Django 2.0 officially supports Oracle 12.1+. +:attr:`AbstractUser.last_name ` ``max_length`` increased to 150 +---------------------------------------------------------------------------------------------------------- + +A migration for :attr:`django.contrib.auth.models.User.last_name` is included. +If you have a custom user model inheriting from ``AbstractUser``, you'll need +to generate and apply a database migration for your user model. + +If you want to preserve the 30 character limit for last names, use a custom +form:: + + from django.contrib.auth.forms import UserChangeForm + + class MyUserChangeForm(UserChangeForm): + last_name = forms.CharField(max_length=30, required=False) + +If you wish to keep this restriction in the admin when editing users, set +``UserAdmin.form`` to use this form:: + + from django.contrib.auth.admin import UserAdmin + from django.contrib.auth.models import User + + class MyUserAdmin(UserAdmin): + form = MyUserChangeForm + + admin.site.unregister(User) + admin.site.register(User, MyUserAdmin) + Miscellaneous -------------