2015-11-02 63 views
2

我有以下模型是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

這有什麼錯我的代碼?

回答

4

objects應該是管理器的一個實例,而不是類本身。

objects = UserProxyManager()