Ticket #9006: queryset_getitem_ordering_fix.diff
File queryset_getitem_ordering_fix.diff, 1009 bytes (added by , 16 years ago) |
---|
-
django/db/models/query.py
213 213 if len(self._result_cache) < bound: 214 214 self._fill_cache(bound - len(self._result_cache)) 215 215 return self._result_cache[k] 216 216 217 qs = self._clone() 218 if not self.model._meta.ordering: 219 qs.query.add_ordering(self.model._meta.pk.name) 217 220 if isinstance(k, slice): 218 qs = self._clone()219 221 if k.start is not None: 220 222 start = int(k.start) 221 223 else: … … 226 228 stop = None 227 229 qs.query.set_limits(start, stop) 228 230 return k.step and list(qs)[::k.step] or qs 231 229 232 try: 230 qs = self._clone()231 233 qs.query.set_limits(k, k + 1) 232 234 return list(qs)[0] 233 235 except self.model.DoesNotExist, e: