0
0
mirror of https://github.com/django/django.git synced 2024-11-28 10:48:32 +01:00
django/tests/auth_tests/models/with_integer_username.py
2022-02-07 20:37:05 +01:00

24 lines
681 B
Python

from django.contrib.auth.models import AbstractBaseUser, BaseUserManager
from django.db import models
class IntegerUsernameUserManager(BaseUserManager):
def create_user(self, username, password):
user = self.model(username=username)
user.set_password(password)
user.save(using=self._db)
return user
def get_by_natural_key(self, username):
return self.get(username=username)
class IntegerUsernameUser(AbstractBaseUser):
username = models.IntegerField()
password = models.CharField(max_length=255)
USERNAME_FIELD = "username"
REQUIRED_FIELDS = ["username", "password"]
objects = IntegerUsernameUserManager()