From 185658942721852631255f9b3b8a657addfa9f45 Mon Sep 17 00:00:00 2001 From: Dmitriy Kuzmenko Date: Sun, 3 Nov 2019 14:55:08 +0300 Subject: [PATCH] disabled inline in est, and change currency creator --- apps/establishment/admin.py | 7 ++++--- .../management/commands/add_establishment_currency.py | 8 ++++---- 2 files changed, 8 insertions(+), 7 deletions(-) diff --git a/apps/establishment/admin.py b/apps/establishment/admin.py index 95ee81e2..81d5c2cc 100644 --- a/apps/establishment/admin.py +++ b/apps/establishment/admin.py @@ -57,9 +57,10 @@ class ProductInline(admin.TabularInline): class EstablishmentAdmin(BaseModelAdminMixin, admin.ModelAdmin): """Establishment admin.""" list_display = ['id', '__str__', 'image_tag', ] - inlines = [ - AwardInline, ContactPhoneInline, ContactEmailInline, - ReviewInline, CommentInline, ProductInline] + + # inlines = [ + # AwardInline, ContactPhoneInline, ContactEmailInline, + # ReviewInline, CommentInline, ProductInline] raw_id_fields = ('address',) diff --git a/apps/establishment/management/commands/add_establishment_currency.py b/apps/establishment/management/commands/add_establishment_currency.py index 6840eda8..5f24d473 100644 --- a/apps/establishment/management/commands/add_establishment_currency.py +++ b/apps/establishment/management/commands/add_establishment_currency.py @@ -10,11 +10,11 @@ class Command(BaseCommand): def handle(self, *args, **kwargs): count = 0 - queryset = Establishment.objects.all() + queryset = list(Establishment.objects.filter(address__city__country__isnull=False)) url = 'https://restcountries.eu/rest/v2/name/{country}' - for est in queryset: - if not est.currency and est.address and est.address.city and est.address.city.country: + for est in queryset: + if not est.currency: try: country = est.address.city.country.name_translated resp = requests.get(url=url.format(country=country)) @@ -38,7 +38,7 @@ class Command(BaseCommand): currency.sign = currency_dict.get("symbol"), currency.save() est.currency = currency - est.save() count += 1 + Establishment.objects.bulk_update(queryset, ['currency']) self.stdout.write(self.style.WARNING(f'Created/updated {count} objects.'))