Re: What is reverse() good for? Not really reversing...
Okay, if you take the perspective that it reverses the normal order, it does what it should. But then I don't know why we have such a function in there, as the ordering can easily manipulated. What I expected from the method is, when iterating, to give me the last item instead of the first one an so on.. that has nothing to do with how it sould execute SQL so I don't know why I should state any SQL here. On 2 Mai, 17:51, "Karen Tracey" <[EMAIL PROTECTED]> wrote: > On Fri, May 2, 2008 at 11:11 AM, web-junkie <[EMAIL PROTECTED]> wrote: > > > On 1 Mai, 19:32, "Justin Lilly" <[EMAIL PROTECTED]> wrote: > > > While it may be the long way around, can you not do the following? > > > a = Articles.objects.all()[:3] > > > a.reverse() > > > > That would probably be my solution. > > > That's exactly what I tried, and as I described, it gives you > > something wrong, not the queryset reversed... > > Now, I don't think what it give you is wrong, it's just not what you > wanted/expected. Instead of reversing the result after retrieval/slicing > using the normal ordering, it is reversing the normal ordering and then > retrieving/slicing the result. So, given a sequence with normal ordering: > > a,b,c,x,y.z > > You are looking to get (c,b,a) instead of (z,y,x). Below, you mention a doc > note that explains why it doesn't do what you want by noting that there is > no efficient way in SQL to produce the result you are looking for and say > that is nonsense. If it is nonsense, could you please state the SQL > statement you would use to achieve the result you are looking for? > > Karen > > > > > > > > On Thu, May 1, 2008 at 12:36 PM, web-junkie <[EMAIL PROTECTED]> wrote: > > > > > Hi, > > > > > what is the new reverse() method good for? Seems it just swaps the > > > > order_by statement? > > > > I would appreciate a reverse() method that, if used after slicing, > > > > would actually reverse the queryset. > > > > In the docs it's said: "Django doesn't support that mode of access > > > > (slicing from the end), because it's not possible to do it efficiently > > > > in SQL." > > > > That is nonsense, because reverse should not slice from anywhere, it > > > > should just reverse, and you can do that in python. > > > > So when I have Articles.objects.all()[:3] which gives me a,b,c, > > > > Articles.objects.all()[:3].reverse() would make c,b,a out of it, not > > > > z,y,x! Or am I missing something? > > > > -- > > > Justin Lilly > > > Web Developer/Designerhttp://justinlilly.com-Zitierten Text ausblenden > > - > > > > - Zitierten Text anzeigen -- Zitierten Text ausblenden - > > - Zitierten Text anzeigen - --~--~-~--~~~---~--~~ 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 [EMAIL PROTECTED] For more options, visit this group at http://groups.google.com/group/django-users?hl=en -~--~~~~--~~--~--~---
Re: What is reverse() good for? Not really reversing...
That is what I do at the moment, putting it in a list in such an order that it is reversed. On 2 Mai, 19:58, "J. Cliff Dyer" <[EMAIL PROTECTED]> wrote: > On Thu, 2008-05-01 at 09:36 -0700, web-junkie wrote: > > Hi, > > > what is the newreverse() method good for? Seems it just swaps the > > order_by statement? > > I would appreciate areverse() method that, if used after slicing, > > would actuallyreversethe queryset. > > In the docs it's said: "Django doesn’t support that mode of access > > (slicing from the end), because it’snotpossible to do it efficiently > > in SQL." > > That is nonsense, becausereverseshouldnotslice from anywhere, it > > should justreverse, and you can do that in python. > > So when I have Articles.objects.all()[:3] which gives me a,b,c, > > Articles.objects.all()[:3].reverse() would make c,b,a out of it,not > > z,y,x! Or am I missing something? > > The problem seems to be in getting the ORM to write an appropriate query > to return the results you want. Would it work for your needs if you > pull it out of the queryset into a list, and thenreverseit at the > python level? > > Something like this (untested code follows) > > py>>> arts = Articles.objects.all()[:3] > py>>> arts = list(arts) > py>>> arts.reverse() > > The drawback, of course, is that you no longer have a query set, so > whether this will work for you depends on your use case. > > Cheers, > Cliff --~--~-~--~~~---~--~~ 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 [EMAIL PROTECTED] For more options, visit this group at http://groups.google.com/group/django-users?hl=en -~--~~~~--~~--~--~---
Re: What is reverse() good for? Not really reversing...
On Thu, 2008-05-01 at 09:36 -0700, web-junkie wrote: > Hi, > > what is the new reverse() method good for? Seems it just swaps the > order_by statement? > I would appreciate a reverse() method that, if used after slicing, > would actually reverse the queryset. > In the docs it's said: "Django doesn't support that mode of access > (slicing from the end), because it's not possible to do it efficiently > in SQL." > That is nonsense, because reverse should not slice from anywhere, it > should just reverse, and you can do that in python. > So when I have Articles.objects.all()[:3] which gives me a,b,c, > Articles.objects.all()[:3].reverse() would make c,b,a out of it, not > z,y,x! Or am I missing something? The problem seems to be in getting the ORM to write an appropriate query to return the results you want. Would it work for your needs if you pull it out of the queryset into a list, and then reverse it at the python level? Something like this (untested code follows) py>>> arts = Articles.objects.all()[:3] py>>> arts = list(arts) py>>> arts.reverse() The drawback, of course, is that you no longer have a query set, so whether this will work for you depends on your use case. Cheers, Cliff --~--~-~--~~~---~--~~ 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 [EMAIL PROTECTED] For more options, visit this group at http://groups.google.com/group/django-users?hl=en -~--~~~~--~~--~--~---
Re: What is reverse() good for? Not really reversing...
Interesting. To support your statement, I tried it myself and here's what I got from my shell... In [1]: from aids.trends.models import County In [2]: foo = County.objects.all()[:3] In [3]: foo Out[3]: [, , ] In [4]: foo.reverse() Out[4]: [, , ] In [5]: foo.reverse() Out[5]: [, , ] In [6]: foo Out[6]: [, , ] In [7]: l = [1,2,3] In [8]: l Out[8]: [1, 2, 3] In [9]: l.reverse() In [10]: l Out[10]: [3, 2, 1] And then I fixed it with: In [18]: County.objects.order_by('-id')[County.objects.count()-3:] Out[18]: [, , ] Not sure how, from a performance prospective, that works... but it does work. -justin On Fri, May 2, 2008 at 11:11 AM, web-junkie <[EMAIL PROTECTED]> wrote: > > That's exactly what I tried, and as I described, it gives you > something wrong, not the queryset reversed... > > On 1 Mai, 19:32, "Justin Lilly" <[EMAIL PROTECTED]> wrote: > > While it may be the long way around, can you not do the following? > > a = Articles.objects.all()[:3] > > a.reverse() > > > > That would probably be my solution. > > > > -justin > > > > > > > > > > > > On Thu, May 1, 2008 at 12:36 PM, web-junkie <[EMAIL PROTECTED]> wrote: > > > > > Hi, > > > > > what is the new reverse() method good for? Seems it just swaps the > > > order_by statement? > > > I would appreciate a reverse() method that, if used after slicing, > > > would actually reverse the queryset. > > > In the docs it's said: "Django doesn't support that mode of access > > > (slicing from the end), because it's not possible to do it efficiently > > > in SQL." > > > That is nonsense, because reverse should not slice from anywhere, it > > > should just reverse, and you can do that in python. > > > So when I have Articles.objects.all()[:3] which gives me a,b,c, > > > Articles.objects.all()[:3].reverse() would make c,b,a out of it, not > > > z,y,x! Or am I missing something? > > > > -- > > Justin Lilly > > Web Developer/Designerhttp://justinlilly.com- Zitierten Text ausblenden > - > > > > - Zitierten Text anzeigen - > > > -- Justin Lilly Web Developer/Designer http://justinlilly.com --~--~-~--~~~---~--~~ 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 [EMAIL PROTECTED] For more options, visit this group at http://groups.google.com/group/django-users?hl=en -~--~~~~--~~--~--~---
Re: What is reverse() good for? Not really reversing...
On Fri, May 2, 2008 at 11:11 AM, web-junkie <[EMAIL PROTECTED]> wrote: > > On 1 Mai, 19:32, "Justin Lilly" <[EMAIL PROTECTED]> wrote: > > While it may be the long way around, can you not do the following? > > a = Articles.objects.all()[:3] > > a.reverse() > > > > That would probably be my solution. > > That's exactly what I tried, and as I described, it gives you > something wrong, not the queryset reversed... > Now, I don't think what it give you is wrong, it's just not what you wanted/expected. Instead of reversing the result after retrieval/slicing using the normal ordering, it is reversing the normal ordering and then retrieving/slicing the result. So, given a sequence with normal ordering: a,b,c,x,y.z You are looking to get (c,b,a) instead of (z,y,x). Below, you mention a doc note that explains why it doesn't do what you want by noting that there is no efficient way in SQL to produce the result you are looking for and say that is nonsense. If it is nonsense, could you please state the SQL statement you would use to achieve the result you are looking for? Karen > > > > > > On Thu, May 1, 2008 at 12:36 PM, web-junkie <[EMAIL PROTECTED]> wrote: > > > > > Hi, > > > > > what is the new reverse() method good for? Seems it just swaps the > > > order_by statement? > > > I would appreciate a reverse() method that, if used after slicing, > > > would actually reverse the queryset. > > > In the docs it's said: "Django doesn't support that mode of access > > > (slicing from the end), because it's not possible to do it efficiently > > > in SQL." > > > That is nonsense, because reverse should not slice from anywhere, it > > > should just reverse, and you can do that in python. > > > So when I have Articles.objects.all()[:3] which gives me a,b,c, > > > Articles.objects.all()[:3].reverse() would make c,b,a out of it, not > > > z,y,x! Or am I missing something? > > > > -- > > Justin Lilly > > Web Developer/Designerhttp://justinlilly.com- Zitierten Text ausblenden > - > > > > - Zitierten Text anzeigen - > > > --~--~-~--~~~---~--~~ 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 [EMAIL PROTECTED] For more options, visit this group at http://groups.google.com/group/django-users?hl=en -~--~~~~--~~--~--~---
Re: What is reverse() good for? Not really reversing...
That's exactly what I tried, and as I described, it gives you something wrong, not the queryset reversed... On 1 Mai, 19:32, "Justin Lilly" <[EMAIL PROTECTED]> wrote: > While it may be the long way around, can you not do the following? > a = Articles.objects.all()[:3] > a.reverse() > > That would probably be my solution. > > -justin > > > > > > On Thu, May 1, 2008 at 12:36 PM, web-junkie <[EMAIL PROTECTED]> wrote: > > > Hi, > > > what is the new reverse() method good for? Seems it just swaps the > > order_by statement? > > I would appreciate a reverse() method that, if used after slicing, > > would actually reverse the queryset. > > In the docs it's said: "Django doesn't support that mode of access > > (slicing from the end), because it's not possible to do it efficiently > > in SQL." > > That is nonsense, because reverse should not slice from anywhere, it > > should just reverse, and you can do that in python. > > So when I have Articles.objects.all()[:3] which gives me a,b,c, > > Articles.objects.all()[:3].reverse() would make c,b,a out of it, not > > z,y,x! Or am I missing something? > > -- > Justin Lilly > Web Developer/Designerhttp://justinlilly.com- Zitierten Text ausblenden - > > - Zitierten Text anzeigen - --~--~-~--~~~---~--~~ 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 [EMAIL PROTECTED] For more options, visit this group at http://groups.google.com/group/django-users?hl=en -~--~~~~--~~--~--~---
Re: What is reverse() good for? Not really reversing...
While it may be the long way around, can you not do the following? a = Articles.objects.all()[:3] a.reverse() That would probably be my solution. -justin On Thu, May 1, 2008 at 12:36 PM, web-junkie <[EMAIL PROTECTED]> wrote: > > Hi, > > what is the new reverse() method good for? Seems it just swaps the > order_by statement? > I would appreciate a reverse() method that, if used after slicing, > would actually reverse the queryset. > In the docs it's said: "Django doesn't support that mode of access > (slicing from the end), because it's not possible to do it efficiently > in SQL." > That is nonsense, because reverse should not slice from anywhere, it > should just reverse, and you can do that in python. > So when I have Articles.objects.all()[:3] which gives me a,b,c, > Articles.objects.all()[:3].reverse() would make c,b,a out of it, not > z,y,x! Or am I missing something? > > > -- Justin Lilly Web Developer/Designer http://justinlilly.com --~--~-~--~~~---~--~~ 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 [EMAIL PROTECTED] For more options, visit this group at http://groups.google.com/group/django-users?hl=en -~--~~~~--~~--~--~---
What is reverse() good for? Not really reversing...
Hi, what is the new reverse() method good for? Seems it just swaps the order_by statement? I would appreciate a reverse() method that, if used after slicing, would actually reverse the queryset. In the docs it's said: "Django doesn’t support that mode of access (slicing from the end), because it’s not possible to do it efficiently in SQL." That is nonsense, because reverse should not slice from anywhere, it should just reverse, and you can do that in python. So when I have Articles.objects.all()[:3] which gives me a,b,c, Articles.objects.all()[:3].reverse() would make c,b,a out of it, not z,y,x! Or am I missing something? --~--~-~--~~~---~--~~ 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 [EMAIL PROTECTED] For more options, visit this group at http://groups.google.com/group/django-users?hl=en -~--~~~~--~~--~--~---