This commit is contained in:
Ivan Hörler 2018-01-14 22:11:34 +01:00
parent 5e91470470
commit c7d9e62f05
4 changed files with 11 additions and 11 deletions

View File

@ -1,10 +1,10 @@
from django.conf.urls import url from django.conf.urls import url
from currencies.views import currencies, CurrencyUpdate from currencies.views import currencies, currency_update
urlpatterns = [ urlpatterns = [
url(r'^currencies/$', currencies), url(r'^currencies/$', currencies),
url(r'^ajax/CurrencyUpdate/$', url(r'^ajax/currency_update/$',
CurrencyUpdate, currency_update,
name='CurrencyUpdate'), name='currency_update'),
] ]

View File

@ -10,11 +10,11 @@ from currencies.forms import CurrencyForm
from django.http import JsonResponse from django.http import JsonResponse
def CurrencyUpdate(request): def currency_update(request):
currency = request.GET.get('CurrencyUpdate', None) currency = request.GET.get('currency_update', None)
data = { data = {
'currency': ExchangeRate_name.objects.get( 'currency': ExchangeRate.objects.filter(
currency).id name__name=currency).latest('date')
} }
print('currency: ', currency, 'data: ', data) print('currency: ', currency, 'data: ', data)
return JsonResponse(data) return JsonResponse(data)

View File

@ -1,7 +1,7 @@
$("#CurrencyUpdate").change(function () { $("#currency_update").change(function () {
var currency = $(this).val(); var currency = $(this).val();
$.ajax({ $.ajax({
url: '/ajax/CurrencyUpdate/', url: '/ajax/currency_update/',
data: { data: {
'currency': currency 'currency': currency
}, },

View File

@ -22,7 +22,7 @@
</ul> </ul>
<form action="" method="POST" novalidate> <form action="" method="POST" novalidate>
{% csrf_token %} {% csrf_token %}
<select name="CurrencyUpdate" id="CurrencyUpdate" onchange="this.form.submit()"> <select name="currency_update" id="currency_update" onchange="this.form.submit()">
<option value="CHF">CHF</option> <option value="CHF">CHF</option>
<option value="USD">USD</option> <option value="USD">USD</option>
<option value="GBP">GBP</option> <option value="GBP">GBP</option>