On Tue, Jul 30, 2013 at 6:06 PM, Florian Apolloner <[email protected]>wrote:
> You can always do list(qs)]:-1] though… Although you really shouldn't [1]. As for the reasons for disallowing negative indexes, dcramer's comment in the ticket makes it clear: there is no way to infer what the last item in a query would be, except if you order it descendingly. For what is worth, production code should never rely on any kind of indexing that's not accompanied by an explicit order-by clause, as the default ordering is unrealiable -- at least in PostgreSQL[2], and I assume in other vendors as well[3]. In fact, one might even argue that it would make more sense to disallow any sort of indexing on querysets lacking an explicit .order_by(), in order to enforce best practices, although I would find that a little too strict. The specific one-off case of retrieving a single row for testing/developing/debugging would be best served by the use of .first() which orders by the primary_key by default[4], which therefore yields a different query from the one created by queryset indexing[5]. As it currently stands, the API mirrors the experience in writing a raw query insofar as it is *impossible* to retrieve the last row of a query without explicitly defining an order by clause. For this reason, I'm -1 on the proposed change. Cheers, AT [1] https://docs.djangoproject.com/en/dev/ref/models/querysets/ [2] http://www.postgresql.org/docs/9.2/static/queries-order.html [3] http://stackoverflow.com/a/5628674/447485 [4] https://docs.djangoproject.com/en/dev/ref/models/querysets/#first [5] http://dpaste.com/hold/1323698/ -- You received this message because you are subscribed to the Google Groups "Django developers" group. To unsubscribe from this group and stop receiving emails from it, send an email to [email protected]. To post to this group, send email to [email protected]. Visit this group at http://groups.google.com/group/django-developers. For more options, visit https://groups.google.com/groups/opt_out.
