add image to establishment

This commit is contained in:
alex 2019-10-29 21:54:03 +03:00
parent b41ec3eebd
commit 55bdc7771f
2 changed files with 52 additions and 20 deletions

View File

@ -0,0 +1,30 @@
from django.core.management.base import BaseCommand
from establishment.models import Establishment
from transfer.models import EstablishmentAssets
class Command(BaseCommand):
help = 'Add preview_image_url values from old db to new db'
def handle(self, *args, **kwargs):
count = 0
url = 'https://1dc3f33f6d-3.optimicdn.com/gaultmillau.com/'
raw_qs = EstablishmentAssets.objects.raw(
'''SELECT establishment_assets.id, establishment_id, attachment_suffix_url
FROM establishment_assets
WHERE attachment_file_name IS NOT NULL
AND attachment_suffix_url IS NOT NULL
AND scope = 'public'
AND type = 'Photo'
AND menu_id IS NULL
GROUP BY establishment_id;'''
)
queryset = [vars(query) for query in raw_qs]
for obj in queryset:
establishment = Establishment.objects.filter(old_id=obj['establishment_id']).first()
if establishment:
establishment.preview_image_url = url + obj['attachment_suffix_url']
establishment.save()
count += 1
self.stdout.write(self.style.WARNING(f'Updated {count} objects.'))

View File

@ -99,7 +99,7 @@ class Ezuser(MigrateMixin):
password_hash = models.CharField(max_length=50, blank=True, null=True)
password_hash_type = models.IntegerField()
facebook_id = models.BigIntegerField()
#TODO: в legacy нету таблицы 'CadLevel'
# TODO: в legacy нету таблицы 'CadLevel'
# level = models.ForeignKey('CadLevel', models.DO_NOTHING)
points = models.IntegerField()
@ -478,25 +478,27 @@ class Dishes(MigrateMixin):
db_table = 'dishes'
# class EstablishmentAssets(MigrateMixin):
# using = 'legacy'
#
# establishment = models.ForeignKey('Establishments', models.DO_NOTHING)
# account = models.ForeignKey(Accounts, models.DO_NOTHING, blank=True, null=True)
# menu_id = models.IntegerField(blank=True, null=True)
# type = models.CharField(max_length=64)
# scope = models.CharField(max_length=32)
# created_at = models.DateTimeField()
# updated_at = models.DateTimeField()
# attachment_file_name = models.CharField(max_length=255, blank=True, null=True)
# attachment_content_type = models.CharField(max_length=255, blank=True, null=True)
# geometries = models.CharField(max_length=1024, blank=True, null=True)
# attachment_file_size = models.IntegerField(blank=True, null=True)
# attachment_updated_at = models.DateTimeField(blank=True, null=True)
#
# class Meta:
# managed = False
# db_table = 'establishment_assets'
class EstablishmentAssets(MigrateMixin):
using = 'legacy'
establishment = models.ForeignKey('Establishments', models.DO_NOTHING)
account = models.ForeignKey(Accounts, models.DO_NOTHING, blank=True, null=True)
menu_id = models.IntegerField(blank=True, null=True)
type = models.CharField(max_length=64)
scope = models.CharField(max_length=32)
created_at = models.DateTimeField()
updated_at = models.DateTimeField()
attachment_file_name = models.CharField(max_length=255, blank=True, null=True)
attachment_content_type = models.CharField(max_length=255, blank=True, null=True)
geometries = models.CharField(max_length=1024, blank=True, null=True)
attachment_file_size = models.IntegerField(blank=True, null=True)
attachment_updated_at = models.DateTimeField(blank=True, null=True)
attachment_suffix_url = models.TextField(blank=True, null=True)
class Meta:
managed = False
db_table = 'establishment_assets'
class EstablishmentBacklinks(MigrateMixin):
using = 'legacy'