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:
|
with connections['legacy'].cursor() as cursor:
|
||||||
cursor.execute('''
|
cursor.execute('''
|
||||||
select
|
select
|
||||||
|
distinct
|
||||||
id,
|
id,
|
||||||
country_code_2,
|
country_code_2 as code,
|
||||||
pinterest_page_url,
|
pinterest_page_url,
|
||||||
twitter_page_url,
|
twitter_page_url,
|
||||||
facebook_page_url,
|
facebook_page_url,
|
||||||
|
|
@ -31,11 +32,12 @@ class Command(BaseCommand):
|
||||||
def add_site_settings(self):
|
def add_site_settings(self):
|
||||||
objects=[]
|
objects=[]
|
||||||
for s in tqdm(self.site_sql(), desc='Add site settings'):
|
for s in tqdm(self.site_sql(), desc='Add site settings'):
|
||||||
country = Country.objects.filter(code=s.code)
|
country = Country.objects.filter(code=s.code).first()
|
||||||
sites = SiteSettings.objects.filter(country=country)
|
sites = SiteSettings.objects.filter(subdomain=s.code)
|
||||||
if not sites.exists():
|
if not sites.exists():
|
||||||
objects.append(
|
objects.append(
|
||||||
SiteSettings(
|
SiteSettings(
|
||||||
|
subdomain=s.code,
|
||||||
country=country,
|
country=country,
|
||||||
pinterest_page_url=s.pinterest_page_url,
|
pinterest_page_url=s.pinterest_page_url,
|
||||||
twitter_page_url=s.twitter_page_url,
|
twitter_page_url=s.twitter_page_url,
|
||||||
|
|
@ -43,28 +45,12 @@ class Command(BaseCommand):
|
||||||
instagram_page_url=s.instagram_page_url,
|
instagram_page_url=s.instagram_page_url,
|
||||||
contact_email=s.contact_email,
|
contact_email=s.contact_email,
|
||||||
config=s.config,
|
config=s.config,
|
||||||
ad_config=s.ad_config
|
ad_config=s.ad_config,
|
||||||
|
old_id=s.id
|
||||||
)
|
)
|
||||||
)
|
)
|
||||||
SiteSettings.objects.bulk_create(objects)
|
SiteSettings.objects.bulk_create(objects)
|
||||||
self.stdout.write(self.style.WARNING(f'Add or get tag category 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.'))
|
|
||||||
|
|
||||||
def handle(self, *args, **kwargs):
|
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