Python 在Tastypie中,如何在资源中调用Django classmethod?

Python 在Tastypie中,如何在资源中调用Django classmethod?,python,django,tastypie,Python,Django,Tastypie,我想在API中使用现有的models.py过滤类方法。 问题是,我希望避免两次编写相同的逻辑,并且希望在模型中而不是API中保留逻辑。以下是我现在所做的: 在models.py中: class Deal(models.Model): # some attributes @classmethod def get_filtered_deals(cls, client, owner): return cls.objects.filter(... # compl

我想在API中使用现有的models.py过滤类方法。 问题是,我希望避免两次编写相同的逻辑,并且希望在模型中而不是API中保留逻辑。以下是我现在所做的:

在models.py中:

class Deal(models.Model):
    # some attributes

    @classmethod
    def get_filtered_deals(cls, client, owner):
        return cls.objects.filter(... # complex filtering rules here, I want to keep this logic here, not duplicate it in api.py!!!
但是我被卡住了,因为我不知道如何在我的Tastypie中的交易链接资源中调用get_filtered_deals类方法。我试过这样的方法:

class Deals(ModelResource):

    class Meta(CommonResourceMeta):
        queryset = Deal.objects.all()
        resource_name = "deals"
        list_allowed_methods = ['get']
        authorization = DealAuthorization()

class DealAuthorization(Authorization):
    def read_list(self, object_list, bundle):
        return object_list.get_filtered_deals(
            owner=bundle.request.user,
            client=int(request.GET['arg2']))
这显然不起作用,因为对象列表没有名为get\u filtered\u的方法


谢谢你的帮助

这很简单

class DealAuthorization(Authorization):
    def read_list(self, object_list, bundle):
        object_list = Deal.get_filtered_deals(
            owner=bundle.request.user,
            client=int(request.GET['arg2']))

        return object_list