Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

AttributeError: 'QuerySet' object has no attribute 'model' #97

Open
jonasli opened this issue Dec 20, 2016 · 0 comments
Open

AttributeError: 'QuerySet' object has no attribute 'model' #97

jonasli opened this issue Dec 20, 2016 · 0 comments

Comments

@jonasli
Copy link

jonasli commented Dec 20, 2016

The code is simple:

Models.py

from future import unicode_literals

from mongoengine import *

connect('test',alias='default')

class user(Document):

email = StringField(required=True)  

first_name = StringField(max_length=50) 
last_name = StringField(max_length=50) 

class Comment (EmbeddedDocument):
content=StringField()
name=StringField(max_length=120)

class Post(Document):
title=StringField(max_length=120, required=True)
author = ReferenceField(user,reverse_delete_rule=CASCADE)
tags=ListField(StringField(max_length=30))
comments=ListField(EmbeddedDocumentField(Comment))
meta={'allow_inheritance':True}

class TextPost(Post):
content = StringField()

class ImagePost(Post):
image_path=StringField()

class LinkPost(Post):
link_url=StringField()


BlogModelResources.py

from tastypie.resources import ModelResource
from blog.models import user

class UserResource(ModelResource):
class Meta:
queryset = user.objects.all()

Django (1.10.1)
django-filter (1.0.1)
django-rest-framework-mongoengine (3.3.1)
django-tastypie (0.13.3)
django-tastypie-mongoengine (0.4.6)
djangorestframework (3.5.3)
pymongo (3.4.0)

I always got the error message:

Unhandled exception in thread started by <function wrapper at 0xb618caac>
Traceback (most recent call last):
File "/usr/local/lib/python2.7/dist-packages/django/utils/autoreload.py", line 226, in wrapper
fn(*args, **kwargs)
File "/usr/local/lib/python2.7/dist-packages/django/core/management/commands/runserver.py", line 121, in inner_run
self.check(display_num_errors=True)
File "/usr/local/lib/python2.7/dist-packages/django/core/management/base.py", line 374, in check
include_deployment_checks=include_deployment_checks,
File "/usr/local/lib/python2.7/dist-packages/django/core/management/base.py", line 361, in _run_checks
return checks.run_checks(**kwargs)
File "/usr/local/lib/python2.7/dist-packages/django/core/checks/registry.py", line 81, in run_checks
new_errors = check(app_configs=app_configs)
File "/usr/local/lib/python2.7/dist-packages/django/core/checks/urls.py", line 14, in check_url_config
return check_resolver(resolver)
File "/usr/local/lib/python2.7/dist-packages/django/core/checks/urls.py", line 24, in check_resolver
for pattern in resolver.url_patterns:
File "/usr/local/lib/python2.7/dist-packages/django/utils/functional.py", line 35, in get
res = instance.dict[self.name] = self.func(instance)
File "/usr/local/lib/python2.7/dist-packages/django/urls/resolvers.py", line 313, in url_patterns
patterns = getattr(self.urlconf_module, "urlpatterns", self.urlconf_module)
File "/usr/local/lib/python2.7/dist-packages/django/utils/functional.py", line 35, in get
res = instance.dict[self.name] = self.func(instance)
File "/usr/local/lib/python2.7/dist-packages/django/urls/resolvers.py", line 306, in urlconf_module
return import_module(self.urlconf_name)
File "/usr/lib/python2.7/importlib/init.py", line 37, in import_module
import(name)
File "/home/jonas/django/mysite/mysite/urls.py", line 22, in
url(r'^blog/', include('blog.urls',namespace="blog")),
File "/usr/local/lib/python2.7/dist-packages/django/conf/urls/init.py", line 50, in include
urlconf_module = import_module(urlconf_module)
File "/usr/lib/python2.7/importlib/init.py", line 37, in import_module
import(name)
File "/home/jonas/django/mysite/blog/urls.py", line 5, in
from .api.BlogModelResources import UserResource
File "/home/jonas/django/mysite/blog/api/BlogModelResources.py", line 4, in
class UserResource(ModelResource):
File "/usr/local/lib/python2.7/dist-packages/tastypie/resources.py", line 1769, in new
setattr(meta, 'object_class', meta.queryset.model)
## AttributeError: 'QuerySet' object has no attribute 'model'

can you please help on this?
thank you very much,
Jonas

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant