Switch transfer standard
Add utils Add -d key
This commit is contained in:
parent
288d6cd699
commit
cf7184d7ac
|
|
@ -11,62 +11,62 @@ field[1] - название поля в таблице legacy
|
||||||
NOTE: среди legacy таблиц совпадение для таблицы Address не найдено (Возможно для Address подходит Locations в legacy)
|
NOTE: среди legacy таблиц совпадение для таблицы Address не найдено (Возможно для Address подходит Locations в legacy)
|
||||||
"""
|
"""
|
||||||
|
|
||||||
|
card = {
|
||||||
Country = {
|
"Country": {
|
||||||
"dependencies": None,
|
"dependencies": None,
|
||||||
"fields": {
|
"fields": {
|
||||||
"Cities": {
|
"Cities": {
|
||||||
"code": "country_code_2",
|
"code": "country_code_2",
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
},
|
||||||
}
|
|
||||||
|
|
||||||
|
"Region": {
|
||||||
Region = {
|
"dependencies": ("Country", "Region"),
|
||||||
"dependencies": ("Country", "Region"),
|
"fields": {
|
||||||
"fields": {
|
# нету аналога для поля name
|
||||||
# нету аналога для поля name
|
"Cities": {
|
||||||
"Cities": {
|
"code": "region_code",
|
||||||
"code": "region_code",
|
},
|
||||||
},
|
},
|
||||||
"ForeignKeys": {
|
"relations": {
|
||||||
"parent_region": "Region",
|
"parent_region": "Region",
|
||||||
"country": "Country"
|
"country": "Country"
|
||||||
}
|
}
|
||||||
}
|
},
|
||||||
}
|
|
||||||
|
|
||||||
|
"City": {
|
||||||
City = {
|
"dependencies": ("Country", "Region"),
|
||||||
"dependencies": ("Country", "Region"),
|
"fields": {
|
||||||
"fields": {
|
"Cities": {
|
||||||
"Cities": {
|
"coordinates": (("lat", "latitude"), ("long", "longitude")),
|
||||||
"coordinates": (("lat", "latitude"), ("long", "longitude")),
|
"code": "country_code_2",
|
||||||
"code": "country_code_2",
|
"postal_code": "zip_code",
|
||||||
"postal_code": "zip_code",
|
"is_island": ("is_island", "Boolean")
|
||||||
"is_island": ("is_island", "Boolean")
|
},
|
||||||
|
"CityNames": {
|
||||||
|
"name": "name",
|
||||||
|
},
|
||||||
},
|
},
|
||||||
"CityNames": {
|
"relations": {
|
||||||
"name": "name",
|
|
||||||
},
|
|
||||||
"ForeignKeys": {
|
|
||||||
"region": "Region",
|
"region": "Region",
|
||||||
"country": "Country"
|
"country": "Country"
|
||||||
}
|
}
|
||||||
}
|
},
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
Address = {
|
"Address": {
|
||||||
"dependencies": ("City",),
|
"dependencies": ("City",),
|
||||||
"fields": {
|
"fields": {
|
||||||
# нету аналога для поля number
|
# нету аналога для поля number
|
||||||
"Locations": {
|
"Locations": {
|
||||||
"postal_code": "zip_code",
|
"postal_code": "zip_code",
|
||||||
"coordinates": (("lat", "latitude"), ("long", "longitude"))
|
"coordinates": (("lat", "latitude"), ("long", "longitude"))
|
||||||
|
},
|
||||||
},
|
},
|
||||||
"ForeignKeys": {
|
"relations": {
|
||||||
"city": "City"
|
"city": "City"
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -1,23 +1,30 @@
|
||||||
from django.core.management.base import BaseCommand
|
from django.core.management.base import BaseCommand
|
||||||
from django.apps import apps
|
from django.apps import apps
|
||||||
|
from os.path import exists
|
||||||
|
from importlib.machinery import SourceFileLoader
|
||||||
|
|
||||||
|
from transfer.utils import transfer_objects
|
||||||
|
|
||||||
|
|
||||||
class Command(BaseCommand):
|
class Command(BaseCommand):
|
||||||
help = 'Transfer data between databases'
|
help = 'Transfer data between databases'
|
||||||
|
|
||||||
def handle(self, *args, **options):
|
def handle(self, *args, **options):
|
||||||
for app in apps.get_app_configs():
|
if options['dictionaries']:
|
||||||
if app.name == "location":
|
self._transfer_dictionaries()
|
||||||
print(app.name, ":")
|
|
||||||
|
|
||||||
print(dir(app))
|
|
||||||
for model in app.get_models():
|
|
||||||
print("\t", model)
|
|
||||||
|
|
||||||
def add_arguments(self, parser):
|
def add_arguments(self, parser):
|
||||||
parser.add_argument(
|
parser.add_argument(
|
||||||
'-s',
|
'-d',
|
||||||
'--short',
|
'--dictionaries',
|
||||||
action='store_true',
|
action='store_true',
|
||||||
default=False,
|
default=False,
|
||||||
help='Вывод короткого сообщения'
|
help='Вывод короткого сообщения'
|
||||||
)
|
)
|
||||||
|
|
||||||
|
def _transfer_dictionaries(self):
|
||||||
|
for app in apps.get_app_configs():
|
||||||
|
if exists(f"{app.path}/transfer.py"):
|
||||||
|
card_module = SourceFileLoader("transfer", f"{app.path}/transfer.py").load_module()
|
||||||
|
transfer_objects(app, card_module.card)
|
||||||
|
|
||||||
|
|
|
||||||
6
apps/transfer/utils.py
Normal file
6
apps/transfer/utils.py
Normal file
|
|
@ -0,0 +1,6 @@
|
||||||
|
from collections import OrderedDict
|
||||||
|
|
||||||
|
def transfer_objects(app, transfer_card):
|
||||||
|
for model, card in transfer_card.items():
|
||||||
|
print(model)
|
||||||
|
print(f"\t{card}")
|
||||||
Loading…
Reference in New Issue
Block a user