added transfer for filling city gallery
This commit is contained in:
parent
e6a143f6ea
commit
3f164459a7
|
|
@ -1,8 +1,8 @@
|
||||||
from transfer.serializers import location as location_serializers
|
from transfer.serializers import location as location_serializers
|
||||||
from transfer import models as transfer_models
|
from transfer import models as transfer_models
|
||||||
from location.models import Country
|
from location.models import Country, CityGallery, City
|
||||||
|
from gallery.models import Image
|
||||||
from pprint import pprint
|
from pprint import pprint
|
||||||
|
|
||||||
from requests import get
|
from requests import get
|
||||||
|
|
||||||
|
|
||||||
|
|
@ -179,6 +179,42 @@ def update_flags():
|
||||||
query.save()
|
query.save()
|
||||||
|
|
||||||
|
|
||||||
|
def transfer_city_gallery():
|
||||||
|
created_counter = 0
|
||||||
|
cities_not_exists = {}
|
||||||
|
gallery_obj_exists_counter = 0
|
||||||
|
|
||||||
|
city_gallery = transfer_models.CityPhotos.objects.exclude(city__isnull=True) \
|
||||||
|
.exclude(city__country_code_2__isnull=True) \
|
||||||
|
.exclude(city__country_code_2__iexact='') \
|
||||||
|
.exclude(city__region_code__isnull=True) \
|
||||||
|
.exclude(city__region_code__iexact='') \
|
||||||
|
.values_list('city_id', 'attachment_suffix_url')
|
||||||
|
for old_city_id, image_suffix_url in city_gallery:
|
||||||
|
city = City.objects.filter(old_id=old_city_id)
|
||||||
|
if city.exists():
|
||||||
|
city = city.first()
|
||||||
|
image, _ = Image.objects.get_or_create(image=image_suffix_url,
|
||||||
|
defaults={
|
||||||
|
'image': image_suffix_url,
|
||||||
|
'orientation': Image.HORIZONTAL,
|
||||||
|
'title': f'{city.name} - {image_suffix_url}',
|
||||||
|
})
|
||||||
|
city_gallery, created = CityGallery.objects.get_or_create(image=image,
|
||||||
|
city=city,
|
||||||
|
is_main=True)
|
||||||
|
if created:
|
||||||
|
created_counter += 1
|
||||||
|
else:
|
||||||
|
gallery_obj_exists_counter += 1
|
||||||
|
else:
|
||||||
|
cities_not_exists.update({'city_old_id': old_city_id})
|
||||||
|
|
||||||
|
print(f'Created: {created_counter}\n'
|
||||||
|
f'City not exists: {cities_not_exists}\n'
|
||||||
|
f'Already added: {gallery_obj_exists_counter}')
|
||||||
|
|
||||||
|
|
||||||
data_types = {
|
data_types = {
|
||||||
"dictionaries": [
|
"dictionaries": [
|
||||||
transfer_countries,
|
transfer_countries,
|
||||||
|
|
@ -192,4 +228,5 @@ data_types = {
|
||||||
"update_country_flag": [
|
"update_country_flag": [
|
||||||
update_flags
|
update_flags
|
||||||
],
|
],
|
||||||
|
"fill_city_gallery": [transfer_city_gallery]
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -40,6 +40,7 @@ class Command(BaseCommand):
|
||||||
'product_review',
|
'product_review',
|
||||||
'newsletter_subscriber', # подписчики на рассылку - переносить после переноса пользователей №1
|
'newsletter_subscriber', # подписчики на рассылку - переносить после переноса пользователей №1
|
||||||
'purchased_plaques', # №6 - перенос купленных тарелок
|
'purchased_plaques', # №6 - перенос купленных тарелок
|
||||||
|
'fill_city_gallery', # №3 - перенос галереи городов
|
||||||
]
|
]
|
||||||
|
|
||||||
def handle(self, *args, **options):
|
def handle(self, *args, **options):
|
||||||
|
|
|
||||||
|
|
@ -217,10 +217,10 @@ class CityNames(MigrateMixin):
|
||||||
class CityPhotos(MigrateMixin):
|
class CityPhotos(MigrateMixin):
|
||||||
using = 'legacy'
|
using = 'legacy'
|
||||||
|
|
||||||
# city_id = models.IntegerField(blank=True, null=True)
|
|
||||||
city = models.ForeignKey(Cities, models.DO_NOTHING, blank=True, null=True)
|
city = models.ForeignKey(Cities, models.DO_NOTHING, blank=True, null=True)
|
||||||
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)
|
||||||
|
attachment_suffix_url = models.CharField(max_length=255)
|
||||||
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)
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue
Block a user