You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
As the documentation states, one can restrict the currencies listed on the project by setting the CURRENCIES variable with a list of currency codes on settings.py. I have added the following line to settings.py:
CURRENCIES= ["NOK"]
However, when saving an object with another currency than NOK (e.g., USD), no ValidationError or other exception is raised. Thus, I have added a custom check in my model's clean_fields() method:
classClaim(models.Model):
amount=MoneyField(
max_digits=12,
decimal_places=4,
default_currency="NOK",
validators=[
MinMoneyValidator(0),
MaxMoneyValidator(99999999),
],
)
objects: ClaimManager=money_manager(ClaimManager())
defclean_fields(self, *args: Any, **kwargs: Any):
errors= {}
# Amount currencyifnotself.amount_currencyinsettings.CURRENCIES:
currency_string=", ".join(settings.CURRENCIES)
errors["amount_currency"] = [
_(f"Currency has to be one of {currency_string}")
]
iflen(errors) >0:
raiseValidationError(errors)
# Check model validators:super().clean_fields(*args, **kwargs)
Is this expected behavior? If so, what then does the documentation mean by one can restrict the currencies listed on the project?
The text was updated successfully, but these errors were encountered:
As the documentation states, one can restrict the currencies listed on the project by setting the
CURRENCIES
variable with a list of currency codes onsettings.py
. I have added the following line tosettings.py
:However, when saving an object with another currency than
NOK
(e.g.,USD
), noValidationError
or other exception is raised. Thus, I have added a custom check in my model'sclean_fields()
method:Is this expected behavior? If so, what then does the documentation mean by
one can restrict the currencies listed on the project
?The text was updated successfully, but these errors were encountered: