Skip to content
Advertisement

How to solve MissingRate error in Django?

I want to convert currencies in my Django app. I created a model Customer. In customer model, there are two fields for that credit_limit and currency_choice. I am using django-money for conversion. But I get an error:

MissingRate at /customer Rate GBP -> USD does not exist

How can I solve it?

views.py:

JavaScript

models.py:

JavaScript

settings.py:

JavaScript

traceback:

JavaScript

Advertisement

Answer

I took a quick look at the code that’s rising exceptions. If you take a closer look at line 60 here:

https://github.com/django-money/django-money/blob/b97bd29883f70caf17306a7785405831cbfa59ff/djmoney/contrib/exchange/models.py#L60

that’s the error that’s being raised. 2 lines above you can see a queryset that triggers this error:

JavaScript

I have then noticed that there’s a management command that creates these Rate objects:

https://github.com/django-money/django-money/blob/b97bd29883f70caf17306a7785405831cbfa59ff/djmoney/contrib/exchange/backends/base.py#L59

it seems that you can use the following command:

JavaScript

does this help?

User contributions licensed under: CC BY-SA
7 People found this is helpful
Advertisement