django/tests/auth_tests/models/with_unique_constraint.py

Ignoring revisions in .git-blame-ignore-revs. Click here to bypass and see the normal blame view.

23 lines
686 B
Python
Raw Normal View History

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"),
]