46 lines
		
	
	
		
			1.3 KiB
		
	
	
	
		
			Python
		
	
	
	
	
	
			
		
		
	
	
			46 lines
		
	
	
		
			1.3 KiB
		
	
	
	
		
			Python
		
	
	
	
	
	
| # Generated by Django 3.0.6 on 2020-05-23 16:40
 | |
| 
 | |
| from django.apps.registry import Apps
 | |
| from django.db import migrations, models
 | |
| from django.db.backends.base.schema import BaseDatabaseSchemaEditor
 | |
| 
 | |
| 
 | |
| def create_default_user(apps: Apps, schema_editor: BaseDatabaseSchemaEditor):
 | |
|     # We have to use a direct import here, otherwise we get an object manager error
 | |
|     from passbook.core.models import User
 | |
| 
 | |
|     db_alias = schema_editor.connection.alias
 | |
| 
 | |
|     pbadmin, _ = User.objects.using(db_alias).get_or_create(
 | |
|         username="pbadmin", email="root@localhost", name="passbook Default Admin"
 | |
|     )
 | |
|     pbadmin.set_password("pbadmin", signal=False)  # noqa # nosec
 | |
|     pbadmin.save()
 | |
| 
 | |
| 
 | |
| class Migration(migrations.Migration):
 | |
| 
 | |
|     dependencies = [
 | |
|         ("passbook_core", "0002_auto_20200523_1133"),
 | |
|     ]
 | |
| 
 | |
|     operations = [
 | |
|         migrations.RemoveField(
 | |
|             model_name="user",
 | |
|             name="is_superuser",
 | |
|         ),
 | |
|         migrations.RemoveField(
 | |
|             model_name="user",
 | |
|             name="is_staff",
 | |
|         ),
 | |
|         migrations.RunPython(create_default_user),
 | |
|         migrations.AddField(
 | |
|             model_name="user",
 | |
|             name="is_superuser",
 | |
|             field=models.BooleanField(default=False),
 | |
|         ),
 | |
|         migrations.AddField(
 | |
|             model_name="user", name="is_staff", field=models.BooleanField(default=False)
 | |
|         ),
 | |
|     ]
 | 
