You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
tentest/doc/DjangoBlog/accounts/models.py

39 lines
1.6 KiB

This file contains ambiguous Unicode characters!

This file contains ambiguous Unicode characters that may be confused with others in your current locale. If your use case is intentional and legitimate, you can safely ignore this warning. Use the Escape button to highlight these characters.

from django.contrib.auth.models import AbstractUser
from django.db import models
from django.urls import reverse
from django.utils.timezone import now
from django.utils.translation import gettext_lazy as _
from djangoblog.utils import get_current_site
# Create your models here.
class BlogUser(AbstractUser):
#sjt 扩展Django内置用户模型增加博客系统所需的用户属性
nickname = models.CharField(_('nick name'), max_length=100, blank=True) # sjt 用户昵称
creation_time = models.DateTimeField(_('creation time'), default=now) # sjt 账号创建时间
last_modify_time = models.DateTimeField(_('last modify time'), default=now) # sjt 信息最后修改时间
source = models.CharField(_('create source'), max_length=100, blank=True) # sjt 账号创建来源(如注册、后台添加)
def get_absolute_url(self):
#sjt 获取用户详情页的相对URL
return reverse(
'blog:author_detail', kwargs={
'author_name': self.username})
def __str__(self):
#sjt 对象字符串表示,返回用户邮箱
return self.email
def get_full_url(self):
#sjt 获取用户详情页的完整URL包含域名
site = get_current_site().domain
url = "https://{site}{path}".format(site=site,
path=self.get_absolute_url())
return url
class Meta:
ordering = ['-id'] # sjt 按ID倒序排列
verbose_name = _('user') # sjt 模型显示名称
verbose_name_plural = verbose_name
get_latest_by = 'id' # sjt 最新记录按ID判断