disabled inline in est, and change currency creator

This commit is contained in:
Dmitriy Kuzmenko 2019-11-03 14:55:08 +03:00
parent 398a982c82
commit 1856589427
2 changed files with 8 additions and 7 deletions

View File

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

View File

@ -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.'))