Esempio n. 1
0
class MoneyModelDefaultMoneyUSD(models.Model):
    name = models.CharField(max_length=100)
    price = MoneyField(max_digits=12,
                       decimal_places=3,
                       default=Money('123.45', 'USD'))
    zero = MoneyField(max_digits=12,
                      decimal_places=3,
                      default=Money('0', 'USD'))

    def __str__(self):
        return self.name + ' ' + str(self.price)
Esempio n. 2
0
def model_from_db_view(request, amount='0', currency=settings.BASE_CURRENCY):
    # db roundtrip
    instance = SimpleMoneyModel.objects.create(price=Money(amount, currency))
    instance = SimpleMoneyModel.objects.get(pk=instance.pk)

    money = instance.price
    return render_to_response('view.html', {'money': money})
Esempio n. 3
0
class ParametrizedDefaultAsMoneyModel(models.Model):
    """ The simplest possible declaration with a Money object """
    value = MoneyField(max_digits=12,
                       decimal_places=3,
                       default=Money(100, 'JPY'))

    @staticmethod
    def expected_value():
        return Money('100', 'JPY')
Esempio n. 4
0
    def to_internal_value(self, value):
        """
        Validate that the input is a Money accepted number and return a Money
        instance.
        """
        try:
            value = Money(value)
        except IncorrectMoneyInputError:
            self.fail('invalid')

        return self.validate_precision(value)
Esempio n. 5
0
 def test_money_field_serializer(self):
     model = SimpleMoneyModel.objects.create(name='Test',
                                             price=Money(amount='100.00',
                                                         currency='EUR'))
     serializer = SimpleMoneyModelSerializer(model)
     expected = {
         'id': model.pk,
         'name': model.name,
         'price': model.price.amount_rounded,
         'price_currency': model.price.currency,
     }
     assert serializer.data == expected
Esempio n. 6
0
def instance_view(request):
    money = Money('0.0', 'JPY')
    return render_to_response('view.html', {'money': money})
Esempio n. 7
0
def model_view(request):
    instance = SimpleMoneyModel(price=Money('0.0', 'JPY'))
    money = instance.price
    return render_to_response('view.html', {'money': money})
Esempio n. 8
0
 def expected_value():
     return Money('0', settings.BASE_CURRENCY)
Esempio n. 9
0
 def expected_value():
     return Money('100', 'JPY')