django-shop
django-shop copied to clipboard
MoneyFieldWidget
In demo (didn't try anywhere else) the MoneyField is rendered empty on a change form, due to value rendered with currency in number field.
class MoneyFieldWidget(forms.widgets.NumberInput):
def render(self, name, value, attrs=None):
input_field = super(MoneyFieldWidget, self).render(name, value, attrs)
return format_html('{} <strong>{}</strong>', input_field, self.currency_code)
input field is returning:
<input id="id_unit_price" name="unit_price" step="0.001" style="width: 75px; text-align: right" type="number" value="385.00 Kč" />
Hmm. The currency should be appended after the input field. Strange that it's added inside the field. Does this also happen if you use Euro? This is how I deliver DjangoSHOP to my customers.
Yes, EUR does the same. I will try to figure it out. For now I can provide only basic information:
Python 3.5.1 and this release of shop:
git+https://github.com/awesto/django-shop@4952f8f8884f618f56e82e1d0d1a23cc1a377613#egg=django_shop
Problem is, that
value returns MoneyInCZK('380.000')
, which
in case '%s % value
prints '380.00 Kč'
(that is also the behavior of django Input)
Possible solution could be:
def render(self, name, value, attrs=None):
input_field = super(MoneyFieldWidget, self).render(name, value.as_decimal(), attrs)
return format_html('{} <strong>{}</strong>', input_field, self.currency_code)