From 723cccc9d907be6fff22ba56c40750540fe2cfc2 Mon Sep 17 00:00:00 2001 From: "Pavel \"LEdoian\" Turinsky" Date: Wed, 14 Aug 2019 02:06:31 +0200 Subject: [PATCH] =?UTF-8?q?Testdata:=20mo=C5=BEnost=20nemigrovat=20a=20pra?= =?UTF-8?q?covat=20na=20st=C3=A1vaj=C3=ADc=C3=AD=20DB.?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Vhodné asi jen pro debugování migrací --- seminar/management/commands/testdata.py | 17 +++++++++++++++-- 1 file changed, 15 insertions(+), 2 deletions(-) diff --git a/seminar/management/commands/testdata.py b/seminar/management/commands/testdata.py index d770f77b..d7c65367 100644 --- a/seminar/management/commands/testdata.py +++ b/seminar/management/commands/testdata.py @@ -17,13 +17,26 @@ User = django.contrib.auth.get_user_model() class Command(BaseCommand): help = "Clear database and load testing data." + def add_arguments(self, parser): + parser.add_argument( + '--no-clean', + action='store_true', + help='Změny se provedou v aktuální DB, ne v čisté. Aktuální DB se nezachová. (jen k debugování)', + ) + parser.add_argument( + '--no-migrate', + action='store_true', + help='Neprovádět migrace před generováním testovacích dat (jen k debugování)', + ) + def handle(self, *args, **options): assert settings.DEBUG == True dbfile = settings.DATABASES['default']['NAME'] - if os.path.exists(dbfile): + if os.path.exists(dbfile) and not options['no_clean']: os.rename(dbfile, dbfile + '.old') self.stderr.write('Stara databaze prejmenovana na "%s"' % (dbfile + '.old')) - call_command('migrate', no_input=True) + if not options['no_migrate']: + call_command('migrate', no_input=True) self.stdout.write('Vytvarim uzivatele "admin" (heslo "admin") a pseudo-nahodna data ...') create_test_data(size=8) self.stdout.write('Vytvoreno {} uzivatelu, {} skol, {} resitelu, {} rocniku, {} cisel,'