fix currency

This commit is contained in:
Dmitriy Kuzmenko 2019-11-03 17:13:27 +03:00
parent c50cd7c693
commit 924b4e68e9

View File

@ -3,6 +3,7 @@ import requests
from establishment.models import Establishment
from main.models import Currency
from location.models import Country
from django.template.defaultfilters import slugify
class Command(BaseCommand):
@ -23,14 +24,14 @@ class Command(BaseCommand):
if isinstance(country_list, list):
currency_dict = country_list[0].get("currencies")[0]
if currency_dict:
name = currency_dict.get("name")
name = currency_dict['name']
if name:
currency, created = Currency.objects.get_or_create(
slug=currency_dict.get("name").lower(),
slug = slugify(name)
currency, _ = Currency.objects.get_or_create(
slug=slug,
)
if created:
currency.name = {"en-GB": name},
currency.sign = currency_dict.get("symbol"),
currency.sign = currency_dict["symbol"],
currency.save()
establishments = Establishment.objects.filter(address__city__country=country)
establishments.update(currency=currency)