Add date to currencies list

This commit is contained in:
Ivan Hörler 2017-12-27 18:17:14 +01:00
parent 1b7252a669
commit 318d599a2f
7 changed files with 56 additions and 7 deletions

View File

@ -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:

View File

@ -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),
),
]

View File

@ -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'),
),
]

View File

@ -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):

View File

@ -8,11 +8,17 @@
{% if currency_list %}
<ul>
{% for currency in currency_list %}
<li>{{ currency.name }} : {{ currency.exchange_rate_to_chf }}</li>
<li>
{{ currency.date }} :
{{ currency.name }} :
{{ currency.exchange_rate_to_chf }}
</li>
{% endfor %}
</ul>
{% else %}
<p>No categories are available.</p>
<p class="alert">
Something whent wrong, no currencies are available.
</p>
{% endif %}
</div>
</body>

View File

@ -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()

View File

@ -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 = [