diff --git a/django/didgeridoo/currencies/models.py b/django/didgeridoo/currencies/models.py index 5ee16ef..a5014f3 100644 --- a/django/didgeridoo/currencies/models.py +++ b/django/didgeridoo/currencies/models.py @@ -1,5 +1,4 @@ from django.db import models -from django.core.urlresolvers import reverse from decimal import Decimal import datetime @@ -21,7 +20,8 @@ class ExchangeRate_date(models.Model): class ExchangeRate(models.Model): name = models.ForeignKey(ExchangeRate_name) date = models.ForeignKey(ExchangeRate_date) - exchange_rate_to_chf = models.DecimalField(max_digits=12, decimal_places=5) + exchange_rate_to_chf = models.DecimalField(max_digits=12, + decimal_places=5) def __str__(self): return str(self.name) diff --git a/django/didgeridoo/currencies/urls.py b/django/didgeridoo/currencies/urls.py index 0ef97bf..e34aba9 100644 --- a/django/didgeridoo/currencies/urls.py +++ b/django/didgeridoo/currencies/urls.py @@ -1,6 +1,6 @@ from django.conf.urls import url from currencies.views import currencies, currency_update - +from core import views urlpatterns = [ url(r'^currencies/$', currencies), diff --git a/django/didgeridoo/currencies/views.py b/django/didgeridoo/currencies/views.py index 86419ff..06094a2 100644 --- a/django/didgeridoo/currencies/views.py +++ b/django/didgeridoo/currencies/views.py @@ -11,11 +11,12 @@ from django.http import JsonResponse def currency_update(request): + # https://simpleisbetterthancomplex.com/tutorial/2016/08/29/how-to-work-with-ajax-request-with-django.html currency = request.GET.get('currency_update', None) - data = { - 'currency': ExchangeRate.objects.filter( - name__name=currency).latest('date') - } + data = ExchangeRate.objects.filter( + name__name=currency + ).values('exchange_rate_to_chf' + ).latest('date__date') print('currency: ', currency, 'data: ', data) return JsonResponse(data)