31 lines
938 B
Python
31 lines
938 B
Python
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):
|
|
if options['dictionaries']:
|
|
self._transfer_dictionaries()
|
|
|
|
def add_arguments(self, parser):
|
|
parser.add_argument(
|
|
'-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)
|
|
|