56 lines
1.3 KiB
Python
56 lines
1.3 KiB
Python
#!/usr/bin/env python3
|
|
"""
|
|
A custom user model.
|
|
"""
|
|
import string
|
|
|
|
from django.db import models
|
|
from django.contrib.auth.models import AbstractUser
|
|
from django.core.validators import MinLengthValidator, MaxLengthValidator
|
|
|
|
from .validators import CharValidator
|
|
from quest.models import Quest
|
|
|
|
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."
|
|
)
|
|
username = models.CharField(
|
|
'username',
|
|
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],
|
|
error_messages={
|
|
'unique': "A user with that username already exists.",
|
|
},
|
|
)
|
|
first_name = None
|
|
last_name = None
|
|
email = models.EmailField('email address')
|
|
anonymize = models.BooleanField(
|
|
default=True,
|
|
help_text="Let's be honest, your name doesn't add anything to " \
|
|
+ "the conversation."
|
|
)
|
|
subscriptions = models.ManyToManyField(Quest)
|
|
is_active = models.BooleanField(default=False)
|
|
|
|
def get_full_name(self):
|
|
return None
|
|
def get_short_name(self):
|
|
return None
|