The bottom line: in Django 1.10, unicode support was delivered to usernames .
Nuance: it is enabled by default only for Python 3, and for Python 2 it is still only ASCII.
Problem: I am writing a website for both pythons at once (as of 1.11; I can upgrade to 2.1, of course, I can't) and periodically work here and there. When I create a migration in the third python, the junga strives to create a meaningless change that changes the validator to Unicode:
class Migration(migrations.Migration): # ... operations = [ # ... migrations.AlterField( model_name='user', name='username', field=models.CharField(error_messages={'unique': 'A user with that username already exists.'}, help_text='Required. 150 characters or fewer. Letters, digits and @/./+/-/_ only.', max_length=150, unique=True, validators=[django.contrib.auth.validators.UnicodeUsernameValidator()], verbose_name='username'), ), ] After applying this migration, if I create a new migration already in the second python - on the contrary, the junga seeks to roll back everything and return ASCII back:
class Migration(migrations.Migration): # ... operations = [ # ... migrations.AlterField( model_name='user', name='username', field=models.CharField(error_messages={'unique': 'A user with that username already exists.'}, help_text='Required. 150 characters or fewer. Letters, digits and @/./+/-/_ only.', max_length=150, unique=True, validators=[django.contrib.auth.validators.ASCIIUsernameValidator()], verbose_name='username'), ), ] (playing the game “find one difference” :)
I tried to explicitly prescribe a specific validator in the image and likeness of the board from the documentation :
from django.utils.encoding import python_2_unicode_compatible from django.contrib.auth.models import AbstractUser from django.contrib.auth.validators import ASCIIUsernameValidator @python_2_unicode_compatible class User(AbstractUser): username_validator = ASCIIUsernameValidator() # ...и всякие остальные поля ... but absolutely nothing has changed: the creation of migration in the third python is still diligently shoving UnicodeUsernameValidator where it is not necessary, in the second python, respectively, vice versa.
How to pacify jungle and make use of one thing on all pythons if the advice from the documentation does not work?
Is it possible to copy-paste the username field from the AbstractUser sources to yourself completely? And there is no more adequate way?