On Wed, 2009-04-15 at 23:13 -0700, Margie wrote:
[...]
> # PROBLEM IS HERE
> # Find all pdtasks that have an entry in tiles that is in slice 0:4 of
> Tile.objects.all()
> # I think this should return bar as well, but it returns an empty
> list.  WHY???
> (Pdb) PdTask.objects.filter(tiles__in=Tile.objects.all()[0:4])
> []

Are you using Django 1.0.X here? Because nested queryset support only
exists in 1.1-beta and later. Tile.objects.all()[0:4] is a queryset in
that expression and so won't make sense as an rvalue in 1.0.X.

If you are using 1.0.X, you could write that as:

        values = Tile.objects.values_list("id", flat=True)[0:4]
        PdTask.objects.filter(tiles__in=values)
        
or you could use the slightly ugly hack involving ".query" described in
[1]

[1] http://docs.djangoproject.com/en/dev/ref/models/querysets/#in

Also, I hope your Tasks model has a Meta.ordering specification,
otherwise you could well start seeing all sorts of unexpected (but
completely correct) results when using slices. Database servers are not
required to serve up results in any particular order (or even the same
order on successive queries) unless you specify an ordering.

Regards,
Malcolm


--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the Google Groups 
"Django users" group.
To post to this group, send email to django-users@googlegroups.com
To unsubscribe from this group, send email to 
django-users+unsubscr...@googlegroups.com
For more options, visit this group at 
http://groups.google.com/group/django-users?hl=en
-~----------~----~----~----~------~----~------~--~---

Reply via email to