- 论坛徽章:
- 0
|
本帖最后由 liaozd 于 2014-11-11 16:21 编辑
- class AbstractUser(AbstractBaseUser, PermissionsMixin):
- """
- An abstract base class implementing a fully featured User model with
- admin-compliant permissions.
- Username, password and email are required. Other fields are optional.
- """
- ##### 这里的_('username')等,为什么前面要加下划线呢? #####
- username = models.CharField(_('username'), max_length=30, unique=True,
- help_text=_('Required. 30 characters or fewer. Letters, digits and '
- '@/./+/-/_ only.'),
- validators=[
- validators.RegexValidator(r'^[\w.@+-]+, _('Enter a valid username.'), 'invalid')
- ])
- first_name = models.CharField(_('first name'), max_length=30, blank=True)
- last_name = models.CharField(_('last name'), max_length=30, blank=True)
- email = models.EmailField(_('email address'), blank=True)
- .....
- .....
- class Meta: ##### 这个Meta在这里是起什么作用,我记得python类好像没有这么定义的 #####
- verbose_name = _('user')
- verbose_name_plural = _('users')
- abstract = True
- def get_full_name(self):
- """
- Returns the first_name plus the last_name, with a space in between.
- """
- full_name = '%s %s' % (self.first_name, self.last_name)
- return full_name.strip()
- ......
- ......
- class User(AbstractUser):
- """
- Users within the Django authentication system are represented by this
- model.
- Username, password and email are required. Other fields are optional.
- """
- class Meta(AbstractUser.Meta):
- swappable = 'AUTH_USER_MODEL' ##### 这里是要做什么?不是很懂了 #####
复制代码 |
|