add image to establishment
This commit is contained in:
parent
b41ec3eebd
commit
55bdc7771f
|
|
@ -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.'))
|
||||||
|
|
@ -99,7 +99,7 @@ class Ezuser(MigrateMixin):
|
||||||
password_hash = models.CharField(max_length=50, blank=True, null=True)
|
password_hash = models.CharField(max_length=50, blank=True, null=True)
|
||||||
password_hash_type = models.IntegerField()
|
password_hash_type = models.IntegerField()
|
||||||
facebook_id = models.BigIntegerField()
|
facebook_id = models.BigIntegerField()
|
||||||
#TODO: в legacy нету таблицы 'CadLevel'
|
# TODO: в legacy нету таблицы 'CadLevel'
|
||||||
|
|
||||||
# level = models.ForeignKey('CadLevel', models.DO_NOTHING)
|
# level = models.ForeignKey('CadLevel', models.DO_NOTHING)
|
||||||
points = models.IntegerField()
|
points = models.IntegerField()
|
||||||
|
|
@ -478,25 +478,27 @@ class Dishes(MigrateMixin):
|
||||||
db_table = 'dishes'
|
db_table = 'dishes'
|
||||||
|
|
||||||
|
|
||||||
# class EstablishmentAssets(MigrateMixin):
|
class EstablishmentAssets(MigrateMixin):
|
||||||
# using = 'legacy'
|
using = 'legacy'
|
||||||
#
|
|
||||||
# establishment = models.ForeignKey('Establishments', models.DO_NOTHING)
|
establishment = models.ForeignKey('Establishments', models.DO_NOTHING)
|
||||||
# account = models.ForeignKey(Accounts, models.DO_NOTHING, blank=True, null=True)
|
account = models.ForeignKey(Accounts, models.DO_NOTHING, blank=True, null=True)
|
||||||
# menu_id = models.IntegerField(blank=True, null=True)
|
menu_id = models.IntegerField(blank=True, null=True)
|
||||||
# type = models.CharField(max_length=64)
|
type = models.CharField(max_length=64)
|
||||||
# scope = models.CharField(max_length=32)
|
scope = models.CharField(max_length=32)
|
||||||
# created_at = models.DateTimeField()
|
created_at = models.DateTimeField()
|
||||||
# updated_at = models.DateTimeField()
|
updated_at = models.DateTimeField()
|
||||||
# attachment_file_name = models.CharField(max_length=255, blank=True, null=True)
|
attachment_file_name = models.CharField(max_length=255, blank=True, null=True)
|
||||||
# attachment_content_type = 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)
|
geometries = models.CharField(max_length=1024, blank=True, null=True)
|
||||||
# attachment_file_size = models.IntegerField(blank=True, null=True)
|
attachment_file_size = models.IntegerField(blank=True, null=True)
|
||||||
# attachment_updated_at = models.DateTimeField(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
|
class Meta:
|
||||||
# db_table = 'establishment_assets'
|
managed = False
|
||||||
|
db_table = 'establishment_assets'
|
||||||
|
|
||||||
|
|
||||||
class EstablishmentBacklinks(MigrateMixin):
|
class EstablishmentBacklinks(MigrateMixin):
|
||||||
using = 'legacy'
|
using = 'legacy'
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue
Block a user