diff --git a/django/didgeridoo/currencies/exchange_rates.py b/django/didgeridoo/currencies/exchange_rates.py index 2900892..db1cc6b 100644 --- a/django/didgeridoo/currencies/exchange_rates.py +++ b/django/didgeridoo/currencies/exchange_rates.py @@ -110,7 +110,7 @@ def get_exchange_rate(): # CHFvalue, "CHF and 1 ", base_currency, " costs: ", # FOREIGNvalue_round, target_currency) exchange_rates.update( - {target_currency: FOREIGNvalue_round}) + {target_currency: FOREIGNvalue_round, "date": date}) # Print the Dictionary: # print(exchange_rates) else: diff --git a/django/didgeridoo/currencies/migrations/0002_exchangerate_date.py b/django/didgeridoo/currencies/migrations/0002_exchangerate_date.py new file mode 100644 index 0000000..37fb831 --- /dev/null +++ b/django/didgeridoo/currencies/migrations/0002_exchangerate_date.py @@ -0,0 +1,20 @@ +# -*- coding: utf-8 -*- +# Generated by Django 1.10.7 on 2017-12-27 10:05 +from __future__ import unicode_literals + +from django.db import migrations, models + + +class Migration(migrations.Migration): + + dependencies = [ + ('currencies', '0001_initial'), + ] + + operations = [ + migrations.AddField( + model_name='exchangerate', + name='date', + field=models.DateField(null=True), + ), + ] diff --git a/django/didgeridoo/currencies/migrations/0003_auto_20171227_1119.py b/django/didgeridoo/currencies/migrations/0003_auto_20171227_1119.py new file mode 100644 index 0000000..c6283a2 --- /dev/null +++ b/django/didgeridoo/currencies/migrations/0003_auto_20171227_1119.py @@ -0,0 +1,20 @@ +# -*- coding: utf-8 -*- +# Generated by Django 1.10.7 on 2017-12-27 10:19 +from __future__ import unicode_literals + +from django.db import migrations, models + + +class Migration(migrations.Migration): + + dependencies = [ + ('currencies', '0002_exchangerate_date'), + ] + + operations = [ + migrations.AlterField( + model_name='exchangerate', + name='date', + field=models.DateField(null=True, verbose_name='%Y-%m-%d'), + ), + ] diff --git a/django/didgeridoo/currencies/models.py b/django/didgeridoo/currencies/models.py index 1edbe06..fb6d10c 100644 --- a/django/didgeridoo/currencies/models.py +++ b/django/didgeridoo/currencies/models.py @@ -3,6 +3,7 @@ from django.db import models class ExchangeRate(models.Model): name = models.CharField(max_length=200, unique=True) + date = models.DateField('%Y-%m-%d', null=True) exchange_rate_to_chf = models.FloatField(max_length=5) def __str__(self): diff --git a/django/didgeridoo/currencies/templates/currencies/index.html b/django/didgeridoo/currencies/templates/currencies/index.html index 3c1e8a7..50d944a 100644 --- a/django/didgeridoo/currencies/templates/currencies/index.html +++ b/django/didgeridoo/currencies/templates/currencies/index.html @@ -8,11 +8,17 @@ {% if currency_list %} {% else %} -

No categories are available.

+

+ Something whent wrong, no currencies are available. +

{% endif %} diff --git a/django/didgeridoo/currencies/views.py b/django/didgeridoo/currencies/views.py index 23f8952..4a4450c 100644 --- a/django/didgeridoo/currencies/views.py +++ b/django/didgeridoo/currencies/views.py @@ -6,17 +6,19 @@ from currencies import exchange_rates def currencies(request): # return HttpResponse("exchange_rates") raw_data = exchange_rates.get_exchange_rate() - for i, j in raw_data.items(): + for i, j, k, l in raw_data.items(): if ExchangeRate.objects.filter(name=i): e = ExchangeRate.objects.filter( name=i, ).update( - exchange_rate_to_chf=j + exchange_rate_to_chf=j, + date=l ) else: e = ExchangeRate.objects.create( name=i, - exchange_rate_to_chf=j + exchange_rate_to_chf=j, + date=l ) e.save() currency_list = ExchangeRate.objects.all() diff --git a/django/didgeridoo/didgeridoo/settings.py b/django/didgeridoo/didgeridoo/settings.py index f741185..33c98f9 100644 --- a/django/didgeridoo/didgeridoo/settings.py +++ b/django/didgeridoo/didgeridoo/settings.py @@ -32,7 +32,6 @@ ALLOWED_HOSTS = [] INSTALLED_APPS = [ 'webshop.apps.WebshopConfig', - 'currencies.apps.CurrenciesConfig', 'django_extensions', 'django.contrib.admin', 'django.contrib.auth', @@ -40,6 +39,7 @@ INSTALLED_APPS = [ 'django.contrib.sessions', 'django.contrib.messages', 'django.contrib.staticfiles', + 'currencies', ] MIDDLEWARE = [