Ticket #11283: 11283.diff

File 11283.diff, 1.1 KB (added by Matthias Kestenholz, 14 years ago)
  • django/db/models/query.py

    diff --git a/django/db/models/query.py b/django/db/models/query.py
    index 58f9313..5bc650f 100644
    a b class QuerySet(object):  
    403403                "Cannot change a query once a slice has been taken."
    404404        obj = self._clone()
    405405        obj.query.set_limits(high=1)
     406        obj.query.clear_ordering()
    406407        obj.query.add_ordering('-%s' % latest_by)
    407408        return obj.get()
    408409
  • tests/modeltests/get_latest/tests.py

    diff --git a/tests/modeltests/get_latest/tests.py b/tests/modeltests/get_latest/tests.py
    index 3c3588b..a0f6e94 100644
    a b class LatestTests(TestCase):  
    4343            a3,
    4444        )
    4545
     46        # Checking to ensure latest() overrides any other ordering specified on the query
     47        self.assertEqual(Article.objects.order_by('id').latest(), a4)
     48
    4649    def test_latest_manual(self):
    4750        # You can still use latest() with a model that doesn't have
    4851        # "get_latest_by" set -- just pass in the field name manually.
Back to Top