diff --git a/django/didgeridoo/currencies/urls.py b/django/didgeridoo/currencies/urls.py index 28801cf..ef9dd3f 100644 --- a/django/didgeridoo/currencies/urls.py +++ b/django/didgeridoo/currencies/urls.py @@ -4,4 +4,7 @@ from currencies.views import currencies, CurrencyUpdate urlpatterns = [ url(r'^currencies/$', currencies), + url(r'^ajax/CurrencyUpdate/$', + CurrencyUpdate, + name='CurrencyUpdate'), ] diff --git a/django/didgeridoo/currencies/views.py b/django/didgeridoo/currencies/views.py index 5af1837..a69fb90 100644 --- a/django/didgeridoo/currencies/views.py +++ b/django/didgeridoo/currencies/views.py @@ -7,17 +7,18 @@ from currencies.models import (ExchangeRate, ExchangeRate_name) from currencies import exchange_rates from currencies.forms import CurrencyForm +from django.http import JsonResponse def CurrencyUpdate(request): - if request.method == 'POST': - currency_form = CurrencyForm - assert False - else: - currency_form = CurrencyForm - assert False - return render(request, - {'currency_form': currency_form}) + assert False + currency = request.GET.get('CurrencyUpdate', None) + data = { + 'currency': ExchangeRate_name.objects.filter( + name=currency) + } + return JsonResponse(data) + def currencies(request): # this function fetches the data from exchange_rates.py diff --git a/django/didgeridoo/static/js/app.js b/django/didgeridoo/static/js/app.js new file mode 100644 index 0000000..09c128c --- /dev/null +++ b/django/didgeridoo/static/js/app.js @@ -0,0 +1,15 @@ + $("#id_currency").change(function () { + var currency = $(this).val(); + $.ajax({ + url: '/ajax/CurrencyUpdate/', + data: { + 'currency': currency + }, + dataType: 'json', + success: function (data) { + if (data.is_taken) { + alert("es pop auf! --dies kommt von: static/js/app.js--."); + } + } + }); + }); diff --git a/django/didgeridoo/webshop/urls.py b/django/didgeridoo/webshop/urls.py index dc79c1d..5a4685e 100644 --- a/django/didgeridoo/webshop/urls.py +++ b/django/didgeridoo/webshop/urls.py @@ -11,6 +11,10 @@ urlpatterns = [ views.articles_in_category, name='category'), url('^', include('django.contrib.auth.urls')), - url(r'^profile/$', views.profile, name='profile'), - url(r'^registration/$', views.registration, name='registration'), + url(r'^profile/$', + views.profile, + name='profile'), + url(r'^registration/$', + views.registration, + name='registration'), ] diff --git a/django/didgeridoo/webshop/views.py b/django/didgeridoo/webshop/views.py index 1a4a4db..040f522 100644 --- a/django/didgeridoo/webshop/views.py +++ b/django/didgeridoo/webshop/views.py @@ -11,6 +11,7 @@ from webshop.models import (Article, Picture) from webshop.forms import RegistrationForm + # Create your views here.