django/django — pull request #2392 by fle (2014-03-04 14:39:58+00:00)
Title: Fixed hardcoded call of User model in UserCreationForm

When we implement a custom User model based on AbstractUser, we necessarily
have to write a custom UserCreationForm. If username/password behaviors are
not altered, it seems interesting to simply inerhits from UserCreationForm
with model property of Meta class.

But there was a hardcoded call to User model in clean_username() method
that was forbidding this simple inheritance.

Example :

# ----- models.py ------
from django.contrib.auth.models import AbstractUser

class CustomUser(AbstractUser):
# ....

# ----- admin.py -----
from django.contrib.auth.admin import UserAdmin
from django.contrib.auth.forms import UserCreationForm

class CustomUserCreationForm(UserCreationForm):
class Meta:
model = CustomUser

class CustomUserAdmin(UserAdmin):
add_form = CustomUserCreationForm