On Tuesday 04 December 2007 07:25:31 Gary Wilson wrote: > Sort of my point. Since filter() and [:] both return QuerySets why > should they be any different: > > UTPerson.objects.all().filter(name__startswith='a')[:10]
1) This, logically, should return the first ten people whose 'name' starts with 'a'. > UTPerson.objects.all()[:10].filter(name__startswith='a') 2) This should return the people whose 'name' starts with 'a' from the first 10 rows in the table This is almost certainly what most people would expect (I guess we could argue about that...) But there is no way to specify it in SQL without doing subselects -- you will end up doing 1) instead. Remember that there are other methods that do not or cannot commute e.g. trying to do order_by() after slicing -- it would change the objects that are returned. Just because some methods do happen to commute (filtering) doesn't mean that others should. As an example, I would expect these 2 pieces of code to produce the same result: len(p for p in UTPerson.objects.all()[:10] if p.name[0] == 'a') len(UTPerson.objects.all()[:10].filter(name__startswith='a')) Since we can't make the 2nd match the first, we disallow it. Luke -- "My capacity for happiness you could fit into a matchbox without taking out the matches first." (Marvin the paranoid android) Luke Plant || http://lukeplant.me.uk/ --~--~---------~--~----~------------~-------~--~----~ You received this message because you are subscribed to the Google Groups "Django developers" group. To post to this group, send email to django-developers@googlegroups.com To unsubscribe from this group, send email to [EMAIL PROTECTED] For more options, visit this group at http://groups.google.com/group/django-developers?hl=en -~----------~----~----~----~------~----~------~--~---