diff --git a/django/didgeridoo/currencies/forms.py b/django/didgeridoo/currencies/forms.py index f1df52d..38111bd 100644 --- a/django/didgeridoo/currencies/forms.py +++ b/django/didgeridoo/currencies/forms.py @@ -3,5 +3,13 @@ from currencies.models import ExchangeRate_name class CurrencyForm(forms.Form): - currencies = forms.ModelChoiceField( - queryset=ExchangeRate_name.objects.all()) + # https://bradmontgomery.net/blog/2008/11/24/a-simple-django-example-with-ajax/ + currencies = forms.ModelChoiceField( + queryset=ExchangeRate_name.objects.all()) + + CURRENCY_CHOICES = [(t.name, t.name) for t in + ExchangeRate_name.objects.all()] + + type = forms.ChoiceField(choices=CURRENCY_CHOICES, + widget=forms.Select(attrs={ + 'onchange': 'get_vehicle_color();'})) diff --git a/django/didgeridoo/currencies/views.py b/django/didgeridoo/currencies/views.py index 43c9d29..a4faae6 100644 --- a/django/didgeridoo/currencies/views.py +++ b/django/didgeridoo/currencies/views.py @@ -12,16 +12,15 @@ 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 - if request.method == 'GET': - print('its get method') + if request.GET.get('currency_update', None) == 'CHF': + data = {} else: - print('its not get method') - currency = request.GET.get('currency_update', None) - data = ExchangeRate.objects.filter( - name__name=currency).values( - 'exchange_rate_to_chf').latest( - 'date__date') - print('currency: ', currency, 'data: ', data) + currency = request.GET.get('currency_update', None) + data = ExchangeRate.objects.filter( + name__name=currency).values( + 'exchange_rate_to_chf').latest( + 'date__date') + print('currency:', currency, 'data: ', data) return JsonResponse(data) diff --git a/django/didgeridoo/static/js/app.js b/django/didgeridoo/static/js/app.js index 8bf833f..a9eeae3 100644 --- a/django/didgeridoo/static/js/app.js +++ b/django/didgeridoo/static/js/app.js @@ -1,5 +1,6 @@ - $("#currency_update").change(function () { + $("#id_currency_update").change(function () { var currency_update = $(this).val(); + $("#id_currency_update").val(currency_update); $.ajax({ url: '/ajax/currency_update/', data: { @@ -7,7 +8,22 @@ }, dataType: 'json', success: function (data) { - alert("es pop auf! --dies kommt von: static/js/app.js--.", data); + alert("es pop auf! --dies kommt von: static/js/app.js--."); + } }); }); + + //document.getElementById('id_currency_update').getElementsByTagName('currency_update') + //$("#id_currency_update").val('USD').selected = 'selected'; + + //https://stackoverflow.com/a/30489067/4061870 + // var obj = document.getElementById("id_currency_update"); + // for(i=0; i
  • CART
  • {% if user.is_authenticated %} -
  • - PROFILE -
  • -
  • - LOGOUT -
  • +
  • + PROFILE +
  • +
  • + LOGOUT +
  • {% else %} -
  • - LOGIN -
  • +
  • + LOGIN +
  • {% endif %} + +
    + + {% csrf_token %} +
    -
    - {% csrf_token %} - - -
    + {% endblock %}