From 5f8495a40ab1554e81ac845484da890dd390e1d8 Mon Sep 17 00:00:00 2001 From: Ryan Petrello Date: Tue, 17 Mar 2020 08:12:32 -0400 Subject: [PATCH] Fixed #31371 -- Increased User.first_name max_length to 150 characters. --- AUTHORS | 1 + .../0012_alter_user_first_name_max_length.py | 16 +++++++++++ django/contrib/auth/models.py | 2 +- docs/ref/contrib/auth.txt | 6 +++- docs/releases/3.1.txt | 28 +++++++++++++++++++ 5 files changed, 51 insertions(+), 2 deletions(-) create mode 100644 django/contrib/auth/migrations/0012_alter_user_first_name_max_length.py diff --git a/AUTHORS b/AUTHORS index 220533f648..8e33fc0240 100644 --- a/AUTHORS +++ b/AUTHORS @@ -785,6 +785,7 @@ answer newbie questions, and generally made Django that much better: ryankanno Ryan Kelly Ryan Niemeyer + Ryan Petrello Ryan Rubin Ryno Mathee Sachin Jat diff --git a/django/contrib/auth/migrations/0012_alter_user_first_name_max_length.py b/django/contrib/auth/migrations/0012_alter_user_first_name_max_length.py new file mode 100644 index 0000000000..69f123ff32 --- /dev/null +++ b/django/contrib/auth/migrations/0012_alter_user_first_name_max_length.py @@ -0,0 +1,16 @@ +from django.db import migrations, models + + +class Migration(migrations.Migration): + + dependencies = [ + ('auth', '0011_update_proxy_permissions'), + ] + + operations = [ + migrations.AlterField( + model_name='user', + name='first_name', + field=models.CharField(blank=True, max_length=150, verbose_name='first name'), + ), + ] diff --git a/django/contrib/auth/models.py b/django/contrib/auth/models.py index ce93ee062b..84962b9d0e 100644 --- a/django/contrib/auth/models.py +++ b/django/contrib/auth/models.py @@ -331,7 +331,7 @@ class AbstractUser(AbstractBaseUser, PermissionsMixin): 'unique': _("A user with that username already exists."), }, ) - first_name = models.CharField(_('first name'), max_length=30, blank=True) + first_name = models.CharField(_('first name'), max_length=150, blank=True) last_name = models.CharField(_('last name'), max_length=150, blank=True) email = models.EmailField(_('email address'), blank=True) is_staff = models.BooleanField( diff --git a/docs/ref/contrib/auth.txt b/docs/ref/contrib/auth.txt index b670fadb05..8f591f4c5a 100644 --- a/docs/ref/contrib/auth.txt +++ b/docs/ref/contrib/auth.txt @@ -42,9 +42,13 @@ Fields .. attribute:: first_name - Optional (:attr:`blank=True `). 30 + Optional (:attr:`blank=True `). 150 characters or fewer. + .. versionchanged:: 3.1 + + The ``max_length`` increased from 30 to 150 characters. + .. attribute:: last_name Optional (:attr:`blank=True `). 150 diff --git a/docs/releases/3.1.txt b/docs/releases/3.1.txt index de66d7805f..642575d023 100644 --- a/docs/releases/3.1.txt +++ b/docs/releases/3.1.txt @@ -427,6 +427,34 @@ MariaDB 10.2 and higher. The admin no longer supports the legacy Internet Explorer browser. See :ref:`the admin FAQ ` for details on supported browsers. +:attr:`AbstractUser.first_name ` ``max_length`` increased to 150 +------------------------------------------------------------------------------------------------------------ + +A migration for :attr:`django.contrib.auth.models.User.first_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 first names, use a custom +form:: + + from django import forms + from django.contrib.auth.forms import UserChangeForm + + class MyUserChangeForm(UserChangeForm): + first_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 -------------