I've found the best way to solve these problems is to use a values_list queryset and inject the result of the into the outer query. Django is smart and doesn't actually evaluate the values_list query and instead injects that as a sub query in the SQL.
However in this case can't you simply do: User.objects.filter(quiz__score__gt=90). ? I guess it depends on what sort of relationship you have between user and quiz, but if quiz has a foreign key of user (which your snippet implies), then this should work. Euan On May 24, 3:23 pm, omat <[email protected]> wrote: > ops, this doesn't work, because the the Quiz model is pointing to the > User model, and i want to filter on the quiz model and get the > matching User instances. but in the example in the docs, the query is > on the parent model. > > quiz_qs = Quiz.objects.filter(score__gt=90) > User.objects.filter(quiz__in=quiz_qs) > > is not possible as User does not have a quiz attribute. > > and daniel, yours, saying "user.id in Quiz queryset" does not look ok: > User.objects.filter(id__in=Quiz.objects.filter(score__gt=90)) > > Still stuck. Any ideas? > > -- > oMat > > On May 24, 4:58 pm, omat <[email protected]> wrote: > > > > > @cliff: you are right, but i am writing an extension to an existing > > app. i want to use the models as-is if possible. > > > i found the part in the docs: > > > inner_qs = Blog.objects.filter(name__contains='Cheddar') > > entries = Entry.objects.filter(blog__in=inner_qs) > > > thanks. > > > On May 24, 4:22 pm, Tomasz Zieliński > > > <[email protected]> wrote: > > > On 24 Maj, 08:58, Daniel Roseman <[email protected]> wrote: > > > > > User.objects.filter(id__in=Quiz.objects.filter(score__gt=90)) > > > > Nice thing, is it documented somewhere (I think I haven't this > > > before) ? > > > > -- > > > Tomasz Zielinskihttp://pyconsultant.eu > > > > -- > > > You received this message because you are subscribed to the Google Groups > > > "Django users" group. > > > To post to this group, send email to [email protected]. > > > To unsubscribe from this group, send email to > > > [email protected]. > > > For more options, visit this group > > > athttp://groups.google.com/group/django-users?hl=en. > > > -- > > You received this message because you are subscribed to the Google Groups > > "Django users" group. > > To post to this group, send email to [email protected]. > > To unsubscribe from this group, send email to > > [email protected]. > > For more options, visit this group > > athttp://groups.google.com/group/django-users?hl=en. > > -- > You received this message because you are subscribed to the Google Groups > "Django users" group. > To post to this group, send email to [email protected]. > To unsubscribe from this group, send email to > [email protected]. > For more options, visit this group > athttp://groups.google.com/group/django-users?hl=en. -- You received this message because you are subscribed to the Google Groups "Django users" group. To post to this group, send email to [email protected]. To unsubscribe from this group, send email to [email protected]. For more options, visit this group at http://groups.google.com/group/django-users?hl=en.

