I'm trying to localize where I put my currency symbols in my django template (before vs after the number and spacing are both important). Example:
<span>{{ price }} {{ some_model.currency }}</span>
Where:
some_model
is an object, with propertycurrency
which is a symbol eg "€" or "$" or "RMB".- In addition to the currency, I also know the locale
some_model.locale
.
In consulting the localization docs it seems that django can format times and numbers, but not currencies? I could write a custom filter {{ price | currency_filter }}
, but how do I set (and subsequently get) the session locale in the filter code? Ideally, I'd like to be able to set session's locale upon login, much like you can set the language:
from django.utils.translation import LANGUAGE_SESSION_KEY
def login_view (request):
...
request.session[LANGUAGE_SESSION_KEY] = some_model.locale
and then write some sort of template filter:
def currency_filter (number):
#hopefully some inbuilt session method to get the locale, then:
if locale == 'en-US':
return '$' + number
#etc
Is this possible?