Skip to content

Commit

Permalink
Fixed PendingDeprecationWarning during form initialization. Closes
Browse files Browse the repository at this point in the history
…#262 (#263)

* Fixed ``PendingDeprecationWarning`` during form initialization. Closes #262

* Fix lint

* Fix for Django <= 1.6
  • Loading branch information
Stranger6667 committed Feb 17, 2017
1 parent 172e117 commit 1dc367b
Show file tree
Hide file tree
Showing 3 changed files with 13 additions and 1 deletion.
2 changes: 1 addition & 1 deletion djmoney/models/fields.py
Expand Up @@ -409,7 +409,7 @@ def get_default(self):
def formfield(self, **kwargs):
defaults = {'form_class': forms.MoneyField}
defaults.update(kwargs)
defaults['currency_choices'] = self.currency_choices
defaults['choices'] = self.currency_choices
defaults['default_currency'] = self.default_currency
if self.default is not None:
defaults['default_amount'] = self.default.amount
Expand Down
2 changes: 2 additions & 0 deletions docs/changes.rst
Expand Up @@ -9,6 +9,7 @@ Changes in 0.10.2dev
- Added ability to configure decimal places output. `#154`_, `#251`_ (`ivanchenkodmitry`_)
- Fixed handling of ``defaults`` keyword argument in ``get_or_create`` method. `#257`_ (`kjagiello`_)
- Fixed handling of currency fields lookups in ``get_or_create`` method. `#258`_ (`Stranger6667`_)
- Fixed ``PendingDeprecationWarning`` during form initialization. `#262`_ (`Stranger6667`_, `spookylukey`_)

Changes in 0.10.1
-----------------
Expand Down Expand Up @@ -186,6 +187,7 @@ Changes in 0.3
- South support: Declare default attribute values. (`pjdelport`_)


.. _#262: https://github.com/django-money/django-money/issues/262
.. _#258: https://github.com/django-money/django-money/issues/258
.. _#257: https://github.com/django-money/django-money/pull/257
.. _#251: https://github.com/django-money/django-money/pull/251
Expand Down
10 changes: 10 additions & 0 deletions tests/test_form.py
Expand Up @@ -11,6 +11,7 @@
import pytest

import moneyed
from djmoney.models.fields import MoneyField
from moneyed import Money

from .testapp.forms import (
Expand Down Expand Up @@ -121,3 +122,12 @@ def test_fields_default_amount_becomes_forms_initial():
"""
form = DefaultMoneyModelForm()
assert form.fields['money'].initial == [123, 'PLN']


def test_no_deprecation_warning():
"""
The library's code shouldn't generate any warnings itself. See #262.
"""
with pytest.warns(None) as warning:
MoneyField(max_digits=10, decimal_places=2, currency_choices=(('USD', 'USD'),)).formfield()
assert not warning

0 comments on commit 1dc367b

Please sign in to comment.