seddonym
seddonym

Reputation: 17229

How do I configure django-money to output GBP in British format?

I'm using django-money to handle money amounts in GBP (Pounds Sterling), but they are being output as GB£20.00, rather than £20.00. This is despite settings.LANGUAGE_CODE being "en-GB" and settings.USE_L10N being True.

What am I doing wrong?

Upvotes: 1

Views: 281

Answers (1)

seddonym
seddonym

Reputation: 17229

Django-money uses pymoneyed for handling localization, but unfortunately at the time of writing, pymoneyed isn't set up properly to handle GBP localization. I've created a pull request which fixes it so hopefully this will be fixed at some point.

In the meantime, you can configure your Django installation to handle it correctly by adding the following code anywhere that will get called when Django is run (such as in a models.py).

import moneyed
from moneyed.localization import _FORMATTER
from decimal import ROUND_HALF_EVEN

# A unicode GBP sign
POUND_SIGN = u'\u00A3'

_FORMATTER.add_formatting_definition("en_GB",
    group_size=3, group_separator=",", decimal_point=".",
    positive_sign="", trailing_positive_sign="",
    negative_sign="-", trailing_negative_sign="",
    rounding_method=ROUND_HALF_EVEN)
_FORMATTER.add_sign_definition('en_GB', moneyed.GBP, prefix=POUND_SIGN)

Upvotes: 2

Related Questions