Tastypie Resource Model

I am working on a tastypie with mongoengine. I have a core file, but when I use them in a resource file, it gives me an error:

'QuerySet' object has no attribute 'model'


Resource file

class GameResource(ModelResource):
class Meta:
    queryset = Sports.objects.all()
    resource_name = 'sports'    


kernel file

from mongoengine import *
class Sports(Document):
    game = StringField(max_length=50,required=True)
    name = StringField(max_length=50,required=True)


Here are the error messages I receive:

{"error_message": "", "traceback": "Traceback (most recent call last):\n\n  File \"c:\\virtualenvs\\env\\lib\\site-packages\\django_tastypie-0.9.11-
py2.6.egg\\tastypie\\resources.py\", line 192, in wrapper\n    
response = callback(request, *args, **kwargs)\n\n  File \"c:\\virtualenvs\\env\\lib\\site-packages\\django_tastypie-0.9.11-py2.6.egg\\tastypie\\resources.py\", 
line 397, in dispatch_list\n    return self.dispatch('list', request, **kwargs)\n\n  File \"c:\\virtualenvs\\env\\lib\\site-packages\\django_tastypie-0.9.11-py2.6.egg\\tastypie\\resources.py\", line 427, in dispatch\n    
response = method(request, **kwargs)\n\n  File \"c:\\virtualenvs\\env\\lib\\site-packages\\django_tastypie-0.9.11-py2.6.egg\\tastypie\\resources.py\",
line 1029, in get_list\n    objects = self.obj_get_list(request=request, **self.remove_api_resource_names(kwargs))\n\n  File \"c:\\virtualenvs\\env\\lib\\site-packages\\django_tastypie-0.9.11-py2.6.egg\\tastypie\\resources.py\", line 884, in obj_get_list\n    raise NotImplementedError()\n\nNotImplementedError\n"}



source to share

2 answers

Of course your indentation is wrong, the Meta class must be part of the GameResource class, for example:

class GameResource(ModelResource):
    class Meta:
        queryset = Sports.objects.all()
        resource_name = 'sports'   


If that doesn't fix the problem, could you please insert a complete traceback? The error you mention doesn't seem to be triggered in this code (there is no "model" attribute anywhere). Therefore, it is difficult to understand what the error is and where exactly it is happening.



If anyone needs an example of how to create a Tastypie resource model for MongoDB inheriting from Resource, here is a very helpful link:




All Articles