社区所有版块导航
Python
python开源   Django   Python   DjangoApp   pycharm  
DATA
docker   Elasticsearch  
aigc
aigc   chatgpt  
WEB开发
linux   MongoDB   Redis   DATABASE   NGINX   其他Web框架   web工具   zookeeper   tornado   NoSql   Bootstrap   js   peewee   Git   bottle   IE   MQ   Jquery  
机器学习
机器学习算法  
Python88.com
反馈   公告   社区推广  
产品
短视频  
印度
印度  
Py学习  »  Django

django1.6自定义user后,如何访问这个user模型中的用户

blackholll • 11 年前 • 5628 次点击  

新建了个app:account。account下models.py中写了自己的MyUser模块. 我现在要查询这个MyUser模块中的用户,如何查询? 系统默认的user的话:

from django.contrib.auth.models import User
User.objects.all()

我现在改成

AUTH_USER_MODEL = 'account.MyUser'

后,如何查询所有用户呢? 我看官网上有这么句话: Instead of referring to User directly, you should reference the user model using django.contrib.auth.get_user_model().

我尝试

from django.contrib.auth.get_user_model() import MyUser

报错:SyntaxError: invalid syntax

Python社区是高质量的Python/Django开发社区
本文地址:http://www.python88.com/topic/386
 
5628 次点击  
文章 [ 1 ]  |  最新文章 11 年前
blackholll
Reply   •   1 楼
blackholll    11 年前

论坛不给力啊 没人回答,自己找到答案了:

from django.contrib.auth import get_user_model
   UserModel = get_user_model()
   UserModel.objects.all()