I know easy way, make a few different fields for needed currencies, but that's not only ugly, but the currencies will be hardcoded. It seems to me be more elegant through django-parler, but I do not quite understand how to do it.
Asked
Active
Viewed 247 times
1
-
From what I've seen, the practice is to always display in the currency that you will be accepting, and show an estimate in the local price. For example, if I visit amazon.ca from the US, it will show CAD, with an approximate USD next to it. I would do this with a template tag. You can easily pull conversions from sites like [fixer](http://fixer.io/). – Brobin Jun 01 '17 at 19:50
2 Answers
2
I think this is the right way:
class CurrencyModel(TranslatableModel):
translations = TranslatedFields(
title = models.CharField(_("Title"), max_length=120),
)
code = models.CharField(_('ISO 4217 code'), max_lenght=3)
def __str__(self):
return self.title
class ItemModel(BaseProduct, TranslatableModel):
slug = models.SlugField(_("Slug"), unique=True)
translations = TranslatedFields(
product_name = models.CharField(_("Item Name"), max_length=256),
item_price = models.FloatField(_("Item price")),
currency = models.ForeignKey(CurrencyModel, verbose_name=_("Currency ")),
)
def get_price(self, request):
money = MoneyMaker(self.currency.code)
return money(self.item_price)

Atterratio
- 445
- 2
- 9
- 25
1
The simplest way to localize prices in django-SHOP, is to use the MoneyInXXX
class. This class can be generated for each currency using the MoneyMaker
factory.
Whenever an amount of a Money class is formatted, it is localized properly.

jrief
- 1,516
- 13
- 9