Titivillus/user/models.py

48 lines
1.1 KiB
Python
Raw Normal View History

2018-08-10 18:55:20 -04:00
#!/usr/bin/env python3
"""
A custom user model.
"""
import string
2018-08-10 18:55:20 -04:00
from django.db import models
from django.contrib.auth.models import AbstractUser
from django.core.validators import MinLengthValidator, MaxLengthValidator
from .validators import CharValidator
2018-08-10 18:55:20 -04:00
class User(AbstractUser):
"""
A custom user model.
"""
username_char = CharValidator(
string.ascii_letters + string.digits,
"Username must only contain alphanumeric characters."
)
username_min = MinLengthValidator(
3,
"Username must contain more than 3 characters."
)
username_max = MaxLengthValidator(
20,
"Username must contain less than 20 characters."
)
2018-08-10 18:55:20 -04:00
username = models.CharField(
'username',
2018-08-10 18:55:20 -04:00
max_length=20,
unique=True,
help_text="Must be between 3 and 20 characters. " \
+ "Letters and digits only.",
validators=[username_char, username_min, username_max],
2018-08-10 18:55:20 -04:00
error_messages={
'unique': "A user with that username already exists.",
},
)
2018-08-10 18:55:20 -04:00
first_name = None
last_name = None
email = models.EmailField('email address')
2018-08-10 18:55:20 -04:00
def get_full_name(self):
return None
def get_short_name(self):
return None