免费注册 查看新帖 |

Chinaunix

  平台 论坛 博客 文库
最近访问板块 发新帖
查看: 1430 | 回复: 0

在看django里面的代码,有几个地方看不懂,哪位大侠指点一下,谢谢 [复制链接]

论坛徽章:
0
发表于 2014-11-11 16:13 |显示全部楼层
本帖最后由 liaozd 于 2014-11-11 16:21 编辑
  1. class AbstractUser(AbstractBaseUser, PermissionsMixin):
  2.     """
  3.     An abstract base class implementing a fully featured User model with
  4.     admin-compliant permissions.

  5.     Username, password and email are required. Other fields are optional.
  6.     """


  7.     ##### 这里的_('username')等,为什么前面要加下划线呢? #####
  8.     username = models.CharField(_('username'), max_length=30, unique=True,
  9.         help_text=_('Required. 30 characters or fewer. Letters, digits and '
  10.                     '@/./+/-/_ only.'),
  11.         validators=[
  12.             validators.RegexValidator(r'^[\w.@+-]+, _('Enter a valid username.'), 'invalid')
  13.         ])
  14.     first_name = models.CharField(_('first name'), max_length=30, blank=True)
  15.     last_name = models.CharField(_('last name'), max_length=30, blank=True)
  16.     email = models.EmailField(_('email address'), blank=True)
  17.     .....
  18.     .....


  19.     class Meta:            ##### 这个Meta在这里是起什么作用,我记得python类好像没有这么定义的 #####
  20.         verbose_name = _('user')
  21.         verbose_name_plural = _('users')
  22.         abstract = True

  23.     def get_full_name(self):
  24.         """
  25.         Returns the first_name plus the last_name, with a space in between.
  26.         """
  27.         full_name = '%s %s' % (self.first_name, self.last_name)
  28.         return full_name.strip()

  29.     ......
  30.     ......


  31. class User(AbstractUser):
  32.     """
  33.     Users within the Django authentication system are represented by this
  34.     model.

  35.     Username, password and email are required. Other fields are optional.
  36.     """
  37.     class Meta(AbstractUser.Meta):
  38.         swappable = 'AUTH_USER_MODEL' ##### 这里是要做什么?不是很懂了 #####
复制代码
您需要登录后才可以回帖 登录 | 注册

本版积分规则 发表回复

  

北京盛拓优讯信息技术有限公司. 版权所有 京ICP备16024965号-6 北京市公安局海淀分局网监中心备案编号:11010802020122 niuxiaotong@pcpop.com 17352615567
未成年举报专区
中国互联网协会会员  联系我们:huangweiwei@itpub.net
感谢所有关心和支持过ChinaUnix的朋友们 转载本站内容请注明原作者名及出处

清除 Cookies - ChinaUnix - Archiver - WAP - TOP