1
0
mirror of https://github.com/django/django.git synced 2024-12-28 20:16:19 +00:00
django/tests/auth_tests/models/with_unique_constraint.py

23 lines
686 B
Python

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