1
|
|
|
from django.db import models |
2
|
|
|
from django.contrib.auth.models import ( |
3
|
|
|
AbstractBaseUser, BaseUserManager, PermissionsMixin) |
4
|
|
|
from django.utils.encoding import python_2_unicode_compatible |
5
|
|
|
|
6
|
|
|
|
7
|
|
|
@python_2_unicode_compatible |
8
|
|
|
class Player(models.Model): |
9
|
|
|
state = models.IntegerField(default=0) |
10
|
|
|
|
11
|
|
|
def __str__(self): |
12
|
|
|
return '#%d' % self.pk |
13
|
|
|
|
14
|
|
|
|
15
|
|
|
@python_2_unicode_compatible |
16
|
|
|
class Abstract(models.Model): |
17
|
|
|
name = models.CharField(max_length=255) |
18
|
|
|
|
19
|
|
|
def __str__(self): |
20
|
|
|
return self.name |
21
|
|
|
|
22
|
|
|
class Meta: |
23
|
|
|
abstract = True |
24
|
|
|
|
25
|
|
|
|
26
|
|
|
class Unregistered(Abstract): |
27
|
|
|
pass |
28
|
|
|
|
29
|
|
|
|
30
|
|
|
class MyUserManager(BaseUserManager): |
31
|
|
|
def create_user(self, username, password=None): |
32
|
|
|
user = self.model(username=username) |
33
|
|
|
user.set_password(password) |
34
|
|
|
user.save(using=self._db) |
35
|
|
|
return user |
36
|
|
|
|
37
|
|
|
def create_superuser(self, username, password): |
38
|
|
|
user = self.create_user(username, password=password) |
39
|
|
|
user.is_superuser = True |
40
|
|
|
user.save(using=self._db) |
41
|
|
|
return user |
42
|
|
|
|
43
|
|
|
|
44
|
|
|
class MyUser(AbstractBaseUser, PermissionsMixin): |
45
|
|
|
username = models.CharField(max_length=255, unique=True) |
46
|
|
|
is_active = models.BooleanField(default=True) |
47
|
|
|
is_staff = models.BooleanField(default=True) |
48
|
|
|
|
49
|
|
|
objects = MyUserManager() |
50
|
|
|
|
51
|
|
|
USERNAME_FIELD = 'username' |
52
|
|
|
|
53
|
|
|
def get_full_name(self): |
54
|
|
|
return self.username |
55
|
|
|
get_short_name = get_full_name |
56
|
|
|
|