Skip to content

Instantly share code, notes, and snippets.

@yoandresaav
Created May 2, 2020 18:45
Show Gist options
  • Save yoandresaav/6d2346e62ba81c0bb0e84e277f0a72a2 to your computer and use it in GitHub Desktop.
Save yoandresaav/6d2346e62ba81c0bb0e84e277f0a72a2 to your computer and use it in GitHub Desktop.
from djmoney.contrib.django_rest_framework import MoneyField
from moneyed import Money, Decimal
class MyMoneyField(MoneyField):
def to_representation(self, obj):
return {
'amount': "%f" % (obj.amount),
'currency': "%s" % (obj.currency),
}
def to_internal_value(self, data):
return Money(Decimal(data), 'THB')
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment