Ah - ok, cool, good to know. I am on 1.1 pre-alpha SVN-9814. Am moving soon to the 1.1. beta. I originally encountered this on a case that wasn't quite what I posted. I had a situation where I was guaranteed that my Task had only a single tile in the tiles field. So I was trying to filter like this:
PdTask.objects.filter(tiles__in=pdTask.objects.all()[0]) IE, I was trying to find all PdTasks that contained a tile that was the same as the single tile in pdTask. Then I started experimenting and began to think that maybe I just didn't understand the manytomany queries at all - thought maybe I was doing it wrong. Anyway, your answer allayed my concerns - I have a workaround, no problem there, just didn't want to find that I was using the queries wrong in general. Malcolm - monitoring this group must be a full time job for you. Thank you so much for all of your responses. Margie On Apr 15, 11:39 pm, Malcolm Tredinnick <malc...@pointy-stick.com> wrote: > 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 -~----------~----~----~----~------~----~------~--~---