Django cannot unpack non-iterable 'Q' object

Pedro Faria

Im trying to use Q to make query in django. Database im using for this class is PostgreSQL.

My model is:

class DataSetPG(models.Model):
tower_code = models.CharField(max_length=20, null=False)
time_stamp = models.DateTimeField(default=datetime.now, null=True, blank=True)
value = models.CharField(max_length=200)

class Meta:
    ordering = ('tower_code',)

def __str__(self):
    return "%s" % self.tower_code

My view is asking for:

DataSetPG.objects.filter(Q(tower_code="something"))

But i got this error:

TypeError: cannot unpack non-iterable Q object

What I'm doing wrong? I tried .get instead of .filter and many many other kinds of stuff, but nothing. Im also using Q for querying in mongo database and works fine.

17slim

Putting my comment as an answer:

You can't use the Mongo Q as a Django Q to my understanding. You should instead import like so:

from mongoengine.queryset.visitor import Q as MongoQ
from django.db.models import Q as DjangoQ

With this, instead of Q(tower_code='something') use DjangoQ(tower_code='something'). Wherever you used the Q from mongoengine, replace it with MongoQ.

Collected from the Internet

Please contact [email protected] to delete if infringement.

edited at
0

Comments

0 comments
Login to comment

Related

cannot unpack non-iterable ModelBase object in django

Python Django: TypeError: cannot unpack non-iterable MatchAll object

Django - cannot unpack non-iterable ManyRelatedManager object

Django : cannot unpack non-iterable int object

Cannot unpack non-iterable SerializerMethodField object in Django DRF

Cannot unpack non-iterable object

Django - (Restrict content from blocked users) Cannot unpack non-iterable ManyRelatedManager object

TypeError: cannot unpack non-iterable int object in Django views function

getting 'cannot unpack non-iterable int object' when creating a model in Django

cannot unpack non-iterable datetime.date object

TypeError: cannot unpack non-iterable GetColorImage object

tensorflow TypeError: cannot unpack non-iterable float object

TypeError: cannot unpack non-iterable NoneType object

Python error "cannot unpack non-iterable int object"

TypeError: cannot unpack non-iterable int object

TypeError at /cart/ cannot unpack non-iterable Cart object

TypeError: cannot unpack non-iterable bool object

Python - Cannot unpack non-iterable int object

Python: TypeError: cannot unpack non-iterable int object

cannot unpack non-iterable int object. BMI Calculator

Python TypeError: cannot unpack non-iterable bool object

Python / TypeError: cannot unpack non-iterable Jugador object

-- TypeError: cannot unpack non-iterable NoneType object

PyAutoGui TypeError: cannot unpack non-iterable NoneType object

TypeError: cannot unpack non-iterable int object (Python)

TypeError: cannot unpack non-iterable Lexer object

Python error- cannot unpack non-iterable NoneType object

"TypeError: cannot unpack non-iterable int object" with filter function

TypeError: cannot unpack non-iterable NoneType object Error