Add date to currencies list
This commit is contained in:
parent
1b7252a669
commit
318d599a2f
|
@ -110,7 +110,7 @@ def get_exchange_rate():
|
||||||
# CHFvalue, "CHF and 1 ", base_currency, " costs: ",
|
# CHFvalue, "CHF and 1 ", base_currency, " costs: ",
|
||||||
# FOREIGNvalue_round, target_currency)
|
# FOREIGNvalue_round, target_currency)
|
||||||
exchange_rates.update(
|
exchange_rates.update(
|
||||||
{target_currency: FOREIGNvalue_round})
|
{target_currency: FOREIGNvalue_round, "date": date})
|
||||||
# Print the Dictionary:
|
# Print the Dictionary:
|
||||||
# print(exchange_rates)
|
# print(exchange_rates)
|
||||||
else:
|
else:
|
||||||
|
|
|
@ -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),
|
||||||
|
),
|
||||||
|
]
|
|
@ -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'),
|
||||||
|
),
|
||||||
|
]
|
|
@ -3,6 +3,7 @@ from django.db import models
|
||||||
|
|
||||||
class ExchangeRate(models.Model):
|
class ExchangeRate(models.Model):
|
||||||
name = models.CharField(max_length=200, unique=True)
|
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)
|
exchange_rate_to_chf = models.FloatField(max_length=5)
|
||||||
|
|
||||||
def __str__(self):
|
def __str__(self):
|
||||||
|
|
|
@ -8,11 +8,17 @@
|
||||||
{% if currency_list %}
|
{% if currency_list %}
|
||||||
<ul>
|
<ul>
|
||||||
{% for currency in currency_list %}
|
{% 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 %}
|
{% endfor %}
|
||||||
</ul>
|
</ul>
|
||||||
{% else %}
|
{% else %}
|
||||||
<p>No categories are available.</p>
|
<p class="alert">
|
||||||
|
Something whent wrong, no currencies are available.
|
||||||
|
</p>
|
||||||
{% endif %}
|
{% endif %}
|
||||||
</div>
|
</div>
|
||||||
</body>
|
</body>
|
||||||
|
|
|
@ -6,17 +6,19 @@ from currencies import exchange_rates
|
||||||
def currencies(request):
|
def currencies(request):
|
||||||
# return HttpResponse("exchange_rates")
|
# return HttpResponse("exchange_rates")
|
||||||
raw_data = exchange_rates.get_exchange_rate()
|
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):
|
if ExchangeRate.objects.filter(name=i):
|
||||||
e = ExchangeRate.objects.filter(
|
e = ExchangeRate.objects.filter(
|
||||||
name=i,
|
name=i,
|
||||||
).update(
|
).update(
|
||||||
exchange_rate_to_chf=j
|
exchange_rate_to_chf=j,
|
||||||
|
date=l
|
||||||
)
|
)
|
||||||
else:
|
else:
|
||||||
e = ExchangeRate.objects.create(
|
e = ExchangeRate.objects.create(
|
||||||
name=i,
|
name=i,
|
||||||
exchange_rate_to_chf=j
|
exchange_rate_to_chf=j,
|
||||||
|
date=l
|
||||||
)
|
)
|
||||||
e.save()
|
e.save()
|
||||||
currency_list = ExchangeRate.objects.all()
|
currency_list = ExchangeRate.objects.all()
|
||||||
|
|
|
@ -32,7 +32,6 @@ ALLOWED_HOSTS = []
|
||||||
|
|
||||||
INSTALLED_APPS = [
|
INSTALLED_APPS = [
|
||||||
'webshop.apps.WebshopConfig',
|
'webshop.apps.WebshopConfig',
|
||||||
'currencies.apps.CurrenciesConfig',
|
|
||||||
'django_extensions',
|
'django_extensions',
|
||||||
'django.contrib.admin',
|
'django.contrib.admin',
|
||||||
'django.contrib.auth',
|
'django.contrib.auth',
|
||||||
|
@ -40,6 +39,7 @@ INSTALLED_APPS = [
|
||||||
'django.contrib.sessions',
|
'django.contrib.sessions',
|
||||||
'django.contrib.messages',
|
'django.contrib.messages',
|
||||||
'django.contrib.staticfiles',
|
'django.contrib.staticfiles',
|
||||||
|
'currencies',
|
||||||
]
|
]
|
||||||
|
|
||||||
MIDDLEWARE = [
|
MIDDLEWARE = [
|
||||||
|
|
Loading…
Reference in New Issue