Commit 6cb8c523 authored by Alexandre Lanceart's avatar Alexandre Lanceart
Browse files

currencies et update ok

parent 43518ac7
......@@ -30,6 +30,7 @@ from backend_app.models.universitySemestersDates import UniversitySemestersDates
from backend_app.models.universityTaggedItem import UniversityTaggedItem
from backend_app.models.userData import UserData
from backend_app.models.version import Version
from backend_app.models.updateDateFixer import updateDateFixer
ALL_MODELS = [
Campus,
......@@ -54,6 +55,7 @@ ALL_MODELS = [
UniversityScholarship,
UniversitySemestersDates,
UniversityTaggedItem,
updateDateFixer,
UserData,
Version,
]
......
# Generated by Django 2.1.7 on 2019-05-27 16:11
from django.db import migrations, models
class Migration(migrations.Migration):
dependencies = [
('backend_app', '0010_auto_20190527_1647'),
]
operations = [
migrations.CreateModel(
name='updateDateFixer',
fields=[
('id', models.AutoField(auto_created=True, primary_key=True, serialize=False, verbose_name='ID')),
('update_date', models.DateField()),
],
options={
'abstract': False,
},
),
]
from django.db import models
from backend_app.models.abstract.base import BaseModel
class updateDateFixer(BaseModel):
update_date = models.DateField()
......@@ -2,7 +2,9 @@ import logging
import os
import requests
from datetime import date
from backend_app.models.currency import Currency
from backend_app.models.updateDateFixer import updateDateFixer
from django.core.management.base import BaseCommand, CommandError
class Command(BaseCommand):
......@@ -24,13 +26,16 @@ class Command(BaseCommand):
logger.info(response)
logger = logging.getLogger("django")
for currency in Currency.objects.all():
for fixer_cur in response.json()['rates']:
if(fixer_cur == currency.code):
currency.one_EUR_in_this_currency = response.json()['rates'][currency.code]
currency.save()
for (k,v) in response.json()['rates'].items():
Currency.objects.update_or_create(
code=k,
defaults={"one_EUR_in_this_currency": v
})
updateDateFixer.objects.update_or_create(
update_date = date.today()
)
for currency in Currency.objects.all():
logger.info(currency.code + " " + str(currency.one_EUR_in_this_currency))
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment