﻿id	summary	reporter	owner	description	type	status	component	version	severity	resolution	keywords	cc	stage	has_patch	needs_docs	needs_tests	needs_better_patch	easy	ui_ux
29807	Custom user model with SlugField username causes `allow_unicode` error in admin	Jesse	Adiyat Mubarak	"After modifying the user model to use a SlugField for the username, I can no longer add or modify users in the Django admin panel because of the following error:
{{{
TypeError at /admin/user/user/6/change/
__init__() got an unexpected keyword argument 'allow_unicode'

Exception location: ...venv/lib/python3.6/site-packages/django/forms/fields.py in __init__, line 213
}}}

Inspecting the SlugField definition you can see that it accepts a param called `allow_unicode`:
{{{
class SlugField(CharField):
    default_validators = [validators.validate_slug]
    description = _(""Slug (up to %(max_length)s)"")

    def __init__(self, *args, max_length=50, db_index=True, allow_unicode=False, **kwargs):
        self.allow_unicode = allow_unicode
        if self.allow_unicode:
            self.default_validators = [validators.validate_unicode_slug]
        super().__init__(*args, max_length=max_length, db_index=db_index, **kwargs)
}}}

My user model is based off the Django auth model:
{{{
class User(AbstractUser):
  username = models.SlugField(""username"", max_length=20, unique=True,
    error_messages={
      ""unique"": ""A user with that username already exists.""
    })

  email = models.EmailField(""email"", unique=True,
    error_messages={
      ""unique"": ""A user with that email already exists.""
    })

  # Users are required to login using their email
  USERNAME_FIELD = ""email""
  REQUIRED_FIELDS = [ ""username"" ]
}}}

The model is registered in the admin panel as follows:
{{{
from django.contrib import admin
from django.contrib.auth.admin import UserAdmin

from .models import User


admin.site.register(User, UserAdmin)
}}}

**The error goes away if I comment out the username field and run a migration to revert back to the old username which uses a CharField.**

requirements.txt:
{{{
argon2-cffi==18.3.0
cffi==1.11.5
Django==2.1.1
djangorestframework==3.8.2
pycparser==2.19
pytz==2018.5
six==1.11.0
}}}
"	Bug	closed	contrib.auth	2.1	Normal	invalid	slugfield allow_unicode error admin		Unreviewed	0	0	0	0	0	0
