Site settings migrate data
This commit is contained in:
parent
f52cc8eccc
commit
3a1e55ba1f
|
|
@ -14,8 +14,9 @@ class Command(BaseCommand):
|
|||
with connections['legacy'].cursor() as cursor:
|
||||
cursor.execute('''
|
||||
select
|
||||
distinct
|
||||
id,
|
||||
country_code_2,
|
||||
country_code_2 as code,
|
||||
pinterest_page_url,
|
||||
twitter_page_url,
|
||||
facebook_page_url,
|
||||
|
|
@ -31,11 +32,12 @@ class Command(BaseCommand):
|
|||
def add_site_settings(self):
|
||||
objects=[]
|
||||
for s in tqdm(self.site_sql(), desc='Add site settings'):
|
||||
country = Country.objects.filter(code=s.code)
|
||||
sites = SiteSettings.objects.filter(country=country)
|
||||
country = Country.objects.filter(code=s.code).first()
|
||||
sites = SiteSettings.objects.filter(subdomain=s.code)
|
||||
if not sites.exists():
|
||||
objects.append(
|
||||
SiteSettings(
|
||||
subdomain=s.code,
|
||||
country=country,
|
||||
pinterest_page_url=s.pinterest_page_url,
|
||||
twitter_page_url=s.twitter_page_url,
|
||||
|
|
@ -43,28 +45,12 @@ class Command(BaseCommand):
|
|||
instagram_page_url=s.instagram_page_url,
|
||||
contact_email=s.contact_email,
|
||||
config=s.config,
|
||||
ad_config=s.ad_config
|
||||
ad_config=s.ad_config,
|
||||
old_id=s.id
|
||||
)
|
||||
)
|
||||
SiteSettings.objects.bulk_create(objects)
|
||||
self.stdout.write(self.style.WARNING(f'Add or get tag category objects.'))
|
||||
|
||||
# def add_category_tag(self):
|
||||
# objects = []
|
||||
# for c in tqdm(self.category_sql(), desc='Add category tags'):
|
||||
# categories = TagCategory.objects.filter(index_name=c.category)
|
||||
# if not categories.exists():
|
||||
# objects.append(
|
||||
# TagCategory(label={"en-GB": c.category},
|
||||
# value_type=c.value_type,
|
||||
# index_name=c.category,
|
||||
# public=True
|
||||
# )
|
||||
# )
|
||||
# else:
|
||||
# categories.update(public=True)
|
||||
# TagCategory.objects.bulk_create(objects)
|
||||
# self.stdout.write(self.style.WARNING(f'Add or get tag category objects.'))
|
||||
SiteSettings.objects.bulk_create(objects)
|
||||
self.stdout.write(self.style.WARNING(f'Add or get tag category objects.'))
|
||||
|
||||
def handle(self, *args, **kwargs):
|
||||
pass
|
||||
self.add_site_settings()
|
||||
18
apps/main/migrations/0037_sitesettings_old_id.py
Normal file
18
apps/main/migrations/0037_sitesettings_old_id.py
Normal file
|
|
@ -0,0 +1,18 @@
|
|||
# Generated by Django 2.2.7 on 2019-11-22 07:45
|
||||
|
||||
from django.db import migrations, models
|
||||
|
||||
|
||||
class Migration(migrations.Migration):
|
||||
|
||||
dependencies = [
|
||||
('main', '0036_auto_20191115_0750'),
|
||||
]
|
||||
|
||||
operations = [
|
||||
migrations.AddField(
|
||||
model_name='sitesettings',
|
||||
name='old_id',
|
||||
field=models.IntegerField(blank=True, null=True),
|
||||
),
|
||||
]
|
||||
Loading…
Reference in New Issue
Block a user