Django的User Model
从django 1.5之后, 用户可以自定义User model,查询某一django项目使用的user model:
python manage.py shell
from django.contrib.auth import get_user_model
get_user_model()
<class 'apps.users.models.UserProfile'>
from datetime import datetime
class BaseModel(models.Model):
add_time = models.DateTimeField(default=datetime.now,verbose_name='添加>时间')
class Meta:
abstract = True #这个属性是定义当前的模型类是不是一个抽象类,不在数据库生成对应的表
Please write an abstract of this article 〔 thesis 〕请写一份这本书〔这篇论文〕的摘要 抽象的(与个别情况相对)
from apps.users.models import BaseModel
class CourseComments(BaseModel):
from django.contrib.auth import get_user_model
UserProfile = get_user_model()
user = models.ForeignKey(UserProfile, on_delete=models.CASCADE, verbose_name="用户")
class CourseComments(BaseModel):
from django.conf import settings
user = models.ForeignKey(settings.AUTH_USER_MODEL, on_delete=models.CASCADE, verbose_name="用户")