Switch transfer standard
Add utils Add -d key
This commit is contained in:
parent
288d6cd699
commit
cf7184d7ac
|
|
@ -11,33 +11,31 @@ field[1] - название поля в таблице legacy
|
|||
NOTE: среди legacy таблиц совпадение для таблицы Address не найдено (Возможно для Address подходит Locations в legacy)
|
||||
"""
|
||||
|
||||
|
||||
Country = {
|
||||
card = {
|
||||
"Country": {
|
||||
"dependencies": None,
|
||||
"fields": {
|
||||
"Cities": {
|
||||
"code": "country_code_2",
|
||||
}
|
||||
}
|
||||
}
|
||||
},
|
||||
|
||||
|
||||
Region = {
|
||||
"Region": {
|
||||
"dependencies": ("Country", "Region"),
|
||||
"fields": {
|
||||
# нету аналога для поля name
|
||||
"Cities": {
|
||||
"code": "region_code",
|
||||
},
|
||||
"ForeignKeys": {
|
||||
},
|
||||
"relations": {
|
||||
"parent_region": "Region",
|
||||
"country": "Country"
|
||||
}
|
||||
}
|
||||
}
|
||||
},
|
||||
|
||||
|
||||
City = {
|
||||
"City": {
|
||||
"dependencies": ("Country", "Region"),
|
||||
"fields": {
|
||||
"Cities": {
|
||||
|
|
@ -49,15 +47,15 @@ City = {
|
|||
"CityNames": {
|
||||
"name": "name",
|
||||
},
|
||||
"ForeignKeys": {
|
||||
},
|
||||
"relations": {
|
||||
"region": "Region",
|
||||
"country": "Country"
|
||||
}
|
||||
}
|
||||
}
|
||||
},
|
||||
|
||||
|
||||
Address = {
|
||||
"Address": {
|
||||
"dependencies": ("City",),
|
||||
"fields": {
|
||||
# нету аналога для поля number
|
||||
|
|
@ -65,8 +63,10 @@ Address = {
|
|||
"postal_code": "zip_code",
|
||||
"coordinates": (("lat", "latitude"), ("long", "longitude"))
|
||||
},
|
||||
"ForeignKeys": {
|
||||
},
|
||||
"relations": {
|
||||
"city": "City"
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
|||
|
|
@ -1,23 +1,30 @@
|
|||
from django.core.management.base import BaseCommand
|
||||
from django.apps import apps
|
||||
from os.path import exists
|
||||
from importlib.machinery import SourceFileLoader
|
||||
|
||||
from transfer.utils import transfer_objects
|
||||
|
||||
|
||||
class Command(BaseCommand):
|
||||
help = 'Transfer data between databases'
|
||||
|
||||
def handle(self, *args, **options):
|
||||
for app in apps.get_app_configs():
|
||||
if app.name == "location":
|
||||
print(app.name, ":")
|
||||
|
||||
print(dir(app))
|
||||
for model in app.get_models():
|
||||
print("\t", model)
|
||||
if options['dictionaries']:
|
||||
self._transfer_dictionaries()
|
||||
|
||||
def add_arguments(self, parser):
|
||||
parser.add_argument(
|
||||
'-s',
|
||||
'--short',
|
||||
'-d',
|
||||
'--dictionaries',
|
||||
action='store_true',
|
||||
default=False,
|
||||
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