obj_get_list

问题描述

我在使用带有tastypie_mongoengine 的django-tastypie 时遇到了问题。因此,我设计了一个模型,用于列出 MongoDB 中集合中的联系人,除了 obj_get_list 外,所有方法都运行良好,当从端点 myhost/api/v1/contacts 调用时会引发此错误

{
    "error": "Invalid resource lookup data provided (mismatched type)."
}

这就是我构建模型的方式:

class ContactResource(resources.MongoEngineResource):


    class Meta:

        queryset = Contact.objects.all()
        allowed_methods = ('get','post')
        resource_name = 'contacts/contact'
        authorization = CustomerObjectsOnlyDjangoAuthorization()
        authentication = ApiKeyAuthentication()
        always_return_data=True
        paginator_class = Paginator
        
        filtering = {
            "customer_id": [ "exact",],"campaigns": ["match","id": ["exact","email": ["exact",}
        
        limit=100
        
    def dehydrate(self,bundle):
        
        customs = bundle.data['customs']
        
        if 'customs' in bundle.data:
            del bundle.data['customs']
            
        excludes = ['customer_id','is_spamtrap']
        
        for exclude in excludes:
            
            if exclude in bundle.data:
                del bundle.data[exclude]

        for c in customs:
            if c.get('k'):
                bundle.data[c['k']] = c['v']
            
        return bundle
        
    def obj_get_list(self,bundle,**kwargs):
        
        if bundle.request.GET.get('campaigns__match'):
            
            campaigns = int(bundle.request.GET.get('campaigns__match'))
            self._Meta.queryset = self._Meta.queryset.filter(__raw__={'campaigns':{'$elemmatch':{'id': campaigns}}})

        if not bundle.request.user.is_staff:

            kwargs['customer_id'] = bundle.request.user.get_profile().customer.id
            self._Meta.queryset = self._Meta.queryset.filter(customer_id=kwargs['customer_id'])

        return super(ContactResource,self).obj_get_list(bundle,**kwargs)

如果我调用端点 myhost/api/v1/contacts/contact/contac-id 我可以创建它并获取特定联系人的数据,但要列出上面提到的所有错误

有什么帮助吗?

解决方法

暂无找到可以解决该程序问题的有效方法,小编努力寻找整理中!

如果你已经找到好的解决方法,欢迎将解决方案带上本链接一起发送给小编。

小编邮箱:dio#foxmail.com (将#修改为@)

相关问答

Selenium Web驱动程序和Java。元素在(x,y)点处不可单击。其...
Python-如何使用点“。” 访问字典成员?
Java 字符串是不可变的。到底是什么意思?
Java中的“ final”关键字如何工作?(我仍然可以修改对象。...
“loop:”在Java代码中。这是什么,为什么要编译?
java.lang.ClassNotFoundException:sun.jdbc.odbc.JdbcOdbc...