2015-06-26 07:59:53 +00:00
|
|
|
# coding=utf-8
|
|
|
|
from django.db import models
|
|
|
|
from django.contrib.auth.models import AbstractBaseUser
|
|
|
|
|
|
|
|
|
|
|
|
class AdminGroup(models.Model):
|
|
|
|
pass
|
|
|
|
|
|
|
|
|
2015-06-29 04:43:17 +00:00
|
|
|
class UserManager(models.Manager):
|
|
|
|
use_in_migrations = True
|
|
|
|
|
|
|
|
def get_by_natural_key(self, username):
|
|
|
|
return self.get(**{self.model.USERNAME_FIELD: username})
|
|
|
|
|
|
|
|
|
2015-06-26 07:59:53 +00:00
|
|
|
class User(AbstractBaseUser):
|
2015-07-18 09:17:33 +00:00
|
|
|
# 用户名
|
2015-06-26 07:59:53 +00:00
|
|
|
username = models.CharField(max_length=30, unique=True)
|
2015-07-18 09:17:33 +00:00
|
|
|
# 真实姓名
|
|
|
|
real_name = models.CharField(max_length=30, blank=True, null=True)
|
2015-06-26 07:59:53 +00:00
|
|
|
admin_group = models.ForeignKey(AdminGroup, null=True, on_delete=models.SET_NULL)
|
|
|
|
|
2015-06-29 04:43:17 +00:00
|
|
|
USERNAME_FIELD = 'username'
|
|
|
|
REQUIRED_FIELDS = []
|
|
|
|
|
|
|
|
objects = UserManager()
|
|
|
|
|
2015-06-26 07:59:53 +00:00
|
|
|
class Meta:
|
|
|
|
db_table = "user"
|