handling all post prevents errors.
This commit is contained in:
parent
d74adc65f4
commit
595d02433c
|
@ -25,3 +25,7 @@ class ExchangeRate(models.Model):
|
||||||
|
|
||||||
def __str__(self):
|
def __str__(self):
|
||||||
return str(self.name)
|
return str(self.name)
|
||||||
|
|
||||||
|
class Meta:
|
||||||
|
# https://simpleisbetterthancomplex.com/tips/2016/10/06/django-tip-17-earliest-and-latest.html
|
||||||
|
get_latest_by = 'name__name'
|
||||||
|
|
|
@ -12,11 +12,8 @@ from django.http import JsonResponse
|
||||||
|
|
||||||
def currency_update(request):
|
def currency_update(request):
|
||||||
# https://simpleisbetterthancomplex.com/tutorial/2016/08/29/how-to-work-with-ajax-request-with-django.html
|
# https://simpleisbetterthancomplex.com/tutorial/2016/08/29/how-to-work-with-ajax-request-with-django.html
|
||||||
currency = request.GET.get('currency_update', None)
|
currency = request.POST.get('currency_update', None)
|
||||||
data = ExchangeRate.objects.filter(
|
data = ExchangeRate.objects.values('exchange_rate_to_chf').latest()
|
||||||
name__name=currency
|
|
||||||
).values('exchange_rate_to_chf'
|
|
||||||
).latest('date__date')
|
|
||||||
print('currency: ', currency, 'data: ', data)
|
print('currency: ', currency, 'data: ', data)
|
||||||
return JsonResponse(data)
|
return JsonResponse(data)
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue