Testdata: možnost nemigrovat a pracovat na stávající DB.
Vhodné asi jen pro debugování migrací
This commit is contained in:
		
							parent
							
								
									fbf288039c
								
							
						
					
					
						commit
						723cccc9d9
					
				
					 1 changed files with 15 additions and 2 deletions
				
			
		|  | @ -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,'  | ||||
|  |  | |||
		Loading…
	
		Reference in a new issue
	
	 Pavel "LEdoian" Turinsky
						Pavel "LEdoian" Turinsky