Gábor Farkas wrote:
> Gábor Farkas wrote:
>> hi,
>>
>> is it intentional that calling __getitem__ on a queryset ignores the 
>> Meta_ordering?
>>
>> for example:
>>
>> ====================================
>> class Thing(Model):
>>      name = SlugField()
>>      pub_date = DateTimeField()
>>
>>      class Meta:
>>          ordering = ['-pub_date']
>> ====================================
>>
>>  >>> Thing.objects.all()
>>
>> 'SELECT <snip> FROM "main_thing" ORDER BY "main_thing"."pub_date" DESC'
>>
>> this orders correctly
>>
>>
>>
>>  >>> Thing.objects.all()[0]
>>
>> SELECT <snip> FROM "main_thing" LIMIT 1
>>
>> this does not.
> 
> some more info... it seems the problems is with the following code:

(sorry, i changed the subject-line + text, when i found out that used 
the wrong term) (slicing => __getitem__ )

after some more research, i arrived here:
> 
> ==================QuerySet============================
>      def get(self, *args, **kwargs):
>          clone = self.filter(*args, **kwargs)
>          if not clone._order_by:
>              clone._order_by = ()
> ======================================================

it was added in
http://code.djangoproject.com/changeset/2393,

which was a merge from
http://code.djangoproject.com/changeset/2392,

which is based on the following discussion:

http://tinyurl.com/sxlcp

so it was a performance (cleanness) optimalization for queryset.get().

it makes sense in the get() case, because get() can be only used if the 
queryset only contains one item.

but the problem is that __getitem__ calls get().


a quick hack, like: http://django.pastebin.com/733366 helps,
and all tests pass.

but i'm not sure if this is the nicest way to solve this problem.

gabor

--~--~---------~--~----~------------~-------~--~----~
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
-~----------~----~----~----~------~----~------~--~---

Reply via email to