mirror of
https://github.com/django/django.git
synced 2025-10-25 22:56:12 +00:00
Fixed #33613 -- Made createsuperuser detect uniqueness of USERNAME_FIELD when using Meta.constraints.
This commit is contained in:
committed by
Mariusz Felisiak
parent
ae506181f7
commit
13a9cde133
22
tests/auth_tests/models/with_unique_constraint.py
Normal file
22
tests/auth_tests/models/with_unique_constraint.py
Normal file
@@ -0,0 +1,22 @@
|
||||
from django.contrib.auth.models import AbstractBaseUser, BaseUserManager
|
||||
from django.db import models
|
||||
|
||||
|
||||
class CustomUserWithUniqueConstraintManager(BaseUserManager):
|
||||
def create_superuser(self, username, password):
|
||||
user = self.model(username=username)
|
||||
user.set_password(password)
|
||||
user.save(using=self._db)
|
||||
return user
|
||||
|
||||
|
||||
class CustomUserWithUniqueConstraint(AbstractBaseUser):
|
||||
username = models.CharField(max_length=150)
|
||||
|
||||
objects = CustomUserWithUniqueConstraintManager()
|
||||
USERNAME_FIELD = "username"
|
||||
|
||||
class Meta:
|
||||
constraints = [
|
||||
models.UniqueConstraint(fields=["username"], name="unique_custom_username"),
|
||||
]
|
||||
Reference in New Issue
Block a user