【发布时间】:2015-11-02 13:47:55
【问题描述】:
我有以下模型,它是 auth.models.User 的代理,我需要在管理界面过滤活跃用户,所以我继承了 auth.models.UserManager 并创建了一个新的 Manager。
#!/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 shell 并测试它并得到错误:
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
我的代码有什么问题?
【问题讨论】:
标签: python django python-3.x django-models