Hello,

According to the documentation:
-https://docs.djangoproject.com/en/dev/topics/db/queries/#queries-over-related-objects

one can query using object instance or instance id:

Entry.objects.filter(blog=b) # Query using object
instanceEntry.objects.filter(blog=b.id) # Query using id from
instanceEntry.objects.filter(blog=5) # Query using id directly

Recently I got TypeError while querying using object instance, same
query using id from instance works ok.

In [9]: list(Question.objects.filter(questionset=q.id).order_by('number'))
Out[9]:
[ <Question: {example: Page 1} (1) Do you drink beer?>,
 <Question: {example: Page 1} (2) What type of beer do you drink
predominantly?>,
 <Question: {example: Page 1} (3) Which of these brands of beer have
you tried?> ]

Here is the trace of the error:

In [7]: q = QuestionSet.objects.get(id=1)

In [8]: list(Question.objects.filter(questionset=q).order_by('number'))

TypeError                                 Traceback (most recent call last)
/Users/work/virtuals/pdss/lib/python2.7/site-packages/django/core/management/commands/shell.pyc
in <module>()
----> 1 list(Question.objects.filter(questionset=q).order_by('number'))

/Users/work/virtuals/pdss/lib/python2.7/site-packages/django/db/models/manager.pyc
in filter(self, *args, **kwargs)
    153
    154     def filter(self, *args, **kwargs):
--> 155         return self.get_query_set().filter(*args, **kwargs)
    156
    157     def aggregate(self, *args, **kwargs):

/Users/work/virtuals/pdss/lib/python2.7/site-packages/django/db/models/query.pyc
in filter(self, *args, **kwargs)
    667         set.
    668         """
--> 669         return self._filter_or_exclude(False, *args, **kwargs)
    670
    671     def exclude(self, *args, **kwargs):

/Users/work/virtuals/pdss/lib/python2.7/site-packages/django/db/models/query.pyc
in _filter_or_exclude(self, negate, *args, **kwargs)
    685             clone.query.add_q(~Q(*args, **kwargs))
    686         else:
--> 687             clone.query.add_q(Q(*args, **kwargs))
    688         return clone
    689

/Users/work/virtuals/pdss/lib/python2.7/site-packages/django/db/models/sql/query.pyc
in add_q(self, q_object, used_aliases, force_having)
   1269                 else:
   1270                     self.add_filter(child, connector, q_object.negated,
-> 1271                             can_reuse=used_aliases,
force_having=force_having)
   1272                 if force_having:
   1273                     self.having.end_subtree()

/Users/work/virtuals/pdss/lib/python2.7/site-packages/django/db/models/sql/query.pyc
in add_filter(self, filter_expr, connector, negate, trim, can_reuse,
process_extras, force_having)
   1200         else:
   1201             self.where.add((Constraint(alias, col, field),
lookup_type, value),
-> 1202                 connector)
   1203
   1204         if negate:

/Users/work/virtuals/pdss/lib/python2.7/site-packages/django/db/models/sql/where.pyc
in add(self, data, connector)
     55             # Consume any generators immediately, so that we
can determine
     56             # emptiness and transform any non-empty values correctly.
---> 57             value = list(value)
     58
     59         # The "value_annotation" parameter is used to pass
auxilliary information

TypeError: 'QuestionSet' object is not iterable




-- 
Çağıl

-- 
You received this message because you are subscribed to the Google Groups 
"Django users" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to django-users+unsubscr...@googlegroups.com.
To post to this group, send email to django-users@googlegroups.com.
Visit this group at http://groups.google.com/group/django-users.
For more options, visit https://groups.google.com/groups/opt_out.

Reply via email to