经理auth.Users代理模型
问题描述:
我有以下模型是auth.models.User的代理,我需要过滤管理界面中的活动用户,所以我继承了auth.models.UserManager并做了一个新的经理。经理auth.Users代理模型
#!/usr/bin/python
# -*- coding: utf-8 -*-
from __future__ import unicode_literals
from django.utils.encoding import python_2_unicode_compatible
from django.contrib import auth
class UserProxyManager(auth.models.UserManager):
def get_queryset(self):
return super(UserProxyManager,self).get_queryset().filter(is_active=True)
@python_2_unicode_compatible
class UserProxy(auth.models.User):
objects = UserProxyManager
class Meta:
proxy = True
verbose_name_plural = 'my_users'
verbose_name = 'my_user'
def __str__(self):
return self.get_full_name()
现在我运行Django的外壳和测试,并得到了错误:
python manage.py shell
>>> UserProxy.objects.all()
Traceback (most recent call last):
File "<console>", line 1, in <module>
TypeError: all() missing 1 required positional argument: 'self'
我使用Django 1.8.4和Python 3.4
这有什么错我的代码?
答
objects
应该是管理器的一个实例,而不是类本身。
objects = UserProxyManager()