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.
DjangoBlog/accounts/models.py

30 lines
1.1 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.db import models
from django.contrib.auth.models import AbstractUser
class CustomUser(AbstractUser):
"""自定义用户模型
继承Django内置的AbstractUser类扩展用户基本信息
"""
# MYT个人简介字段最大长度500字符可为空
bio = models.TextField(max_length=500, blank=True, verbose_name="个人简介")
# MYT头像字段图片将上传到avatars/年/月/目录,可为空
avatar = models.ImageField(upload_to='avatars/%Y/%m/', blank=True, null=True, verbose_name="头像")
# MYT所在地字段最大长度100字符可为空
location = models.CharField(max_length=100, blank=True, verbose_name="所在地")
# MYT个人网站字段URL格式可为空
website = models.URLField(blank=True, verbose_name="个人网站")
class Meta:
# MYT 在Django admin中显示的单数名称
verbose_name = "用户"
# MYT在Django admin中显示的复数名称
verbose_name_plural = "用户"
def __str__(self):
"""字符串表示方法,返回用户名用于显示"""
return self.username