diff --git a/django/db/models/query.py b/django/db/models/query.py
index 5b9f504..a6b8f9f 100644
a
|
b
|
class QuerySet(object):
|
553 | 553 | """ |
554 | 554 | self.query.select_related = other.query.select_related |
555 | 555 | |
556 | | def order_by(self, *field_names): |
| 556 | def order_by(self, *field_names, **kwargs): |
557 | 557 | """ |
558 | 558 | Returns a new QuerySet instance with the ordering changed. |
559 | 559 | """ |
| 560 | # we use **kwargs because python can't do *args, reset=True :( |
560 | 561 | assert self.query.can_filter(), \ |
561 | 562 | "Cannot reorder a query once a slice has been taken." |
562 | 563 | obj = self._clone() |
563 | | obj.query.clear_ordering() |
| 564 | if kwargs.get('reset', True): |
| 565 | obj.query.clear_ordering() |
564 | 566 | obj.query.add_ordering(*field_names) |
565 | 567 | return obj |
566 | 568 | |
diff --git a/tests/modeltests/ordering/models.py b/tests/modeltests/ordering/models.py
index a53d93c..fbd0b88 100644
a
|
b
|
class Article(models.Model):
|
24 | 24 | def __unicode__(self): |
25 | 25 | return self.headline |
26 | 26 | |
| 27 | class Value(models.Model): |
| 28 | name = models.CharField(max_length=100) |
| 29 | count = models.IntegerField() |
| 30 | |
| 31 | def __unicode__(self): |
| 32 | return "%s - %s" % (self.name, self.count) |
| 33 | |
27 | 34 | __test__ = {'API_TESTS':""" |
28 | 35 | # Create a couple of Articles. |
29 | 36 | >>> from datetime import datetime |
… |
… |
__test__ = {'API_TESTS':"""
|
86 | 93 | >>> Article.objects.extra(select={'order': 'pub_date'}, order_by=['order', 'headline']) |
87 | 94 | [<Article: Article 1>, <Article: Article 2>, <Article: Article 3>, <Article: Article 4>] |
88 | 95 | |
| 96 | # using the reset = False kwarg on order_by shouldn't reset ordering |
| 97 | >>> _ = Value.objects.create(name='Apple', count=3) |
| 98 | >>> _ = Value.objects.create(name='Apple', count=5) |
| 99 | >>> _ = Value.objects.create(name='Apple', count=4) |
| 100 | >>> _ = Value.objects.create(name='Bannana', count=4) |
| 101 | >>> qs = Value.objects.order_by('-count') |
| 102 | >>> qs.order_by('-name', reset=False) |
| 103 | [<Value: Apple - 5>, <Value: Bannana - 4>, <Value: Apple - 4>, <Value: Apple - 3>] |
| 104 | |
89 | 105 | """} |