Skip to content

Commit

Permalink
Merge pull request #519 from lieryan/lieryan-money-manager-order-by
Browse files Browse the repository at this point in the history
Fix order_by() not being wrapped by understand_money()
  • Loading branch information
benjaoming committed Oct 17, 2019
2 parents 14f94cf + a80fdf1 commit bcd691f
Show file tree
Hide file tree
Showing 3 changed files with 16 additions and 1 deletion.
2 changes: 1 addition & 1 deletion djmoney/models/managers.py
Original file line number Diff line number Diff line change
Expand Up @@ -206,7 +206,7 @@ def wrapper(*args, **kwargs):
return wrapper


RELEVANT_QUERYSET_METHODS = ("distinct", "get", "get_or_create", "filter", "exclude", "update")
RELEVANT_QUERYSET_METHODS = ("distinct", "get", "get_or_create", "filter", "exclude", "update", "order_by")
EXPAND_EXCLUSIONS = {"get_or_create": ("defaults",)}


Expand Down
3 changes: 3 additions & 0 deletions docs/changes.rst
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ Added
~~~~~

- Support for money descriptor customization. (`Stranger6667`_)
- Fix `order_by()` not returning money-compatible queryset `#519`_ (`lieryan`_)
- Django 3.0 support

Removed
Expand Down Expand Up @@ -759,6 +760,7 @@ Added
.. _#80: https://github.com/django-money/django-money/issues/80
.. _#418: https://github.com/django-money/django-money/issues/418
.. _#411: https://github.com/django-money/django-money/issues/411
.. _#519: https://github.com/django-money/django-money/issues/519

.. _77cc33: https://github.com/77cc33
.. _AlexRiina: https://github.com/AlexRiina
Expand Down Expand Up @@ -803,6 +805,7 @@ Added
.. _ivirabyan: https://github.com/ivirabyan
.. _k8n: https://github.com/k8n
.. _lmdsp: https://github.com/lmdsp
.. _lieryan: https://github.com/lieryan
.. _lobziik: https://github.com/lobziik
.. _mattions: https://github.com/mattions
.. _mithrilstar: https://github.com/mithrilstar
Expand Down
12 changes: 12 additions & 0 deletions tests/test_models.py
Original file line number Diff line number Diff line change
Expand Up @@ -697,3 +697,15 @@ def test_create_with_money(self):
instance = ModelWithSharedCurrency.objects.create(first=value, second=value)
assert instance.first == value
assert instance.second == value


def test_order_by():
def extract_data(instance):
return instance.money, instance.integer

ModelWithVanillaMoneyField.objects.create(money=Money(10, "AUD"), integer=2)
ModelWithVanillaMoneyField.objects.create(money=Money(10, "AUD"), integer=1)
ModelWithVanillaMoneyField.objects.create(money=Money(10, "USD"), integer=3)

qs = ModelWithVanillaMoneyField.objects.order_by("integer").filter(money=Money(10, "AUD"))
assert list(map(extract_data, qs)) == [(Money(10, "AUD"), 1), (Money(10, "AUD"), 2)]

0 comments on commit bcd691f

Please sign in to comment.