Merge branch 'migrate/site_settings' into 'develop'
Migrate/site settings See merge request gm/gm-backend!152
This commit is contained in:
commit
9fbc00a6dd
56
apps/main/management/commands/add_site_settings.py
Normal file
56
apps/main/management/commands/add_site_settings.py
Normal file
|
|
@ -0,0 +1,56 @@
|
|||
from django.core.management.base import BaseCommand
|
||||
from django.db import connections
|
||||
from establishment.management.commands.add_position import namedtuplefetchall
|
||||
from main.models import SiteSettings
|
||||
from location.models import Country
|
||||
from tqdm import tqdm
|
||||
|
||||
|
||||
class Command(BaseCommand):
|
||||
help = '''Add add site settings from old db to new db.
|
||||
Run after country migrate!!!'''
|
||||
|
||||
def site_sql(self):
|
||||
with connections['legacy'].cursor() as cursor:
|
||||
cursor.execute('''
|
||||
select
|
||||
distinct
|
||||
id,
|
||||
country_code_2 as code,
|
||||
pinterest_page_url,
|
||||
twitter_page_url,
|
||||
facebook_page_url,
|
||||
contact_email,
|
||||
config,
|
||||
released,
|
||||
instagram_page_url,
|
||||
ad_config
|
||||
from sites as s
|
||||
''')
|
||||
return namedtuplefetchall(cursor)
|
||||
|
||||
def add_site_settings(self):
|
||||
objects=[]
|
||||
for s in tqdm(self.site_sql(), desc='Add site settings'):
|
||||
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,
|
||||
facebook_page_url=s.facebook_page_url,
|
||||
instagram_page_url=s.instagram_page_url,
|
||||
contact_email=s.contact_email,
|
||||
config=s.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 handle(self, *args, **kwargs):
|
||||
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),
|
||||
),
|
||||
]
|
||||
|
|
@ -69,6 +69,8 @@ class SiteSettings(ProjectBaseMixin):
|
|||
verbose_name=_('AD config'))
|
||||
currency = models.ForeignKey(Currency, on_delete=models.PROTECT, null=True, default=None)
|
||||
|
||||
old_id = models.IntegerField(blank=True, null=True)
|
||||
|
||||
objects = SiteSettingsQuerySet.as_manager()
|
||||
|
||||
class Meta:
|
||||
|
|
|
|||
Loading…
Reference in New Issue
Block a user