diff --git a/money/contrib/django/models/fields.py b/money/contrib/django/models/fields.py index 2ec2f41..d11826f 100644 --- a/money/contrib/django/models/fields.py +++ b/money/contrib/django/models/fields.py @@ -1,7 +1,7 @@ from decimal import Decimal from django.db import models -from django.utils.translation import ugettext_lazy +from django.utils.translation import gettext_lazy from money.contrib.django import forms from money.money import Money @@ -58,6 +58,8 @@ def _set_values(self, obj, amount, currency): obj.__dict__[self.field.currency_field_name] = currency def __get__(self, obj, *args): + if obj is None: + return self amount, currency = self._get_values(obj) if amount is None: return None @@ -67,7 +69,7 @@ def __set__(self, obj, value): if value is None: # Money(0) is False self._set_values(obj, None, '') elif isinstance(value, Money): - self._set_values(obj, value.amount, value.currency) + self._set_values(obj, value.amount, value.currency.code) elif isinstance(value, Decimal): _, currency = self._get_values(obj) # use what is currently set self._set_values(obj, value, currency) @@ -126,12 +128,12 @@ def value_to_string(self, obj): When serializing, we want to output as two values. This will be just the currency part as stored directly in the database. """ - value = self._get_val_from_obj(obj) + value = self.value_from_object(obj) return value class MoneyField(InfiniteDecimalField): - description = ugettext_lazy('An amount and type of currency') + description = gettext_lazy('An amount and type of currency') # Don't extend SubfieldBase since we need to have access to both fields when # to_python is called. We need our code there instead of subfieldBase @@ -248,7 +250,7 @@ def value_to_string(self, obj): Here we only need to output the value. The contributed currency field will get called to output itself """ - value = self._get_val_from_obj(obj) + value = self.value_from_object(obj) return value.amount def formfield(self, **kwargs): @@ -256,6 +258,12 @@ def formfield(self, **kwargs): defaults.update(kwargs) return super(MoneyField, self).formfield(**defaults) + @property + def validators(self): + # Hack around the fact that we inherit from DecimalField but don't hold + # Decimals. The real fix is to stop inheriting from DecimalField. + return [] + # South introspection rules # (see http://south.aeracode.org/docs/customfields.html#extending-introspection) diff --git a/money/money.py b/money/money.py index b91f53d..7f552f9 100644 --- a/money/money.py +++ b/money/money.py @@ -355,7 +355,7 @@ def __ge__(self, other): CURRENCY['MDL'] = Currency(code='MDL', numeric='498', decimals=2, symbol=u'', name=u'Moldovan Leu', countries=[u'MOLDOVA, REPUBLIC OF']) CURRENCY['MGA'] = Currency(code='MGA', numeric='969', decimals=2, symbol=u'', name=u'Malagasy Ariary', countries=[u'MADAGASCAR']) CURRENCY['MKD'] = Currency(code='MKD', numeric='807', decimals=2, symbol=u'ден', name=u'Denar', countries=[u'MACEDONIA, THE FORMER YUGOSLAV REPUBLIC OF']) -CURRENCY['MMK'] = Currency(code='MMK', numeric='104', decimals=2, symbol=u'', name=u'Kyat', countries=[u'MYANMAR']) +CURRENCY['MMK'] = Currency(code='MMK', numeric='104', decimals=2, symbol=u'K', name=u'Kyat', countries=[u'MYANMAR']) CURRENCY['MNT'] = Currency(code='MNT', numeric='496', decimals=2, symbol=u'₮', name=u'Tugrik', countries=[u'MONGOLIA']) CURRENCY['MOP'] = Currency(code='MOP', numeric='446', decimals=2, symbol=u'', name=u'Pataca', countries=[u'MACAO']) CURRENCY['MRO'] = Currency(code='MRO', numeric='478', decimals=2, symbol=u'', name=u'Ouguiya', countries=[u'MAURITANIA']) diff --git a/money/tests/views.py b/money/tests/views.py index 4bc8f29..050dff2 100644 --- a/money/tests/views.py +++ b/money/tests/views.py @@ -15,6 +15,7 @@ class SampleForm(forms.Form): class SampleModelForm(forms.ModelForm): class Meta: model = SimpleMoneyModel + fields = '__all__' fields = ( 'name', diff --git a/setup.py b/setup.py index e746c2c..2e4ab6f 100644 --- a/setup.py +++ b/setup.py @@ -38,7 +38,7 @@ def run_tests(self): tests_require = [ 'pytest-django', 'pytest-cov', - 'django<1.9', + 'django<1.10', 'psycopg2', 'six', ] @@ -48,7 +48,7 @@ def run_tests(self): ] extras_require = { - 'django': ['Django < 1.8', ], + 'django': ['Django<1.10', ], } dependency_links = [] diff --git a/version.py b/version.py index f75cef5..e0aeab8 100644 --- a/version.py +++ b/version.py @@ -65,8 +65,12 @@ def call_git_describe(abbrev=5): """ try: - p = Popen(['git', 'describe', '--long', '--tags', '--always', - '--abbrev=%d' % abbrev], stdout=PIPE, stderr=PIPE) + p = Popen( + ['git', 'describe', '--long', '--tags', '--always', '--abbrev=%d' % abbrev], + stdout=PIPE, + stderr=PIPE, + encoding='utf-8', + ) p.stderr.close() line = p.stdout.readlines()[0].strip()