Created
          January 21, 2019 15:03 
        
      - 
      
 - 
        
Save electrofelix/3ae19a692e5a9794acd8b87ac9ddb578 to your computer and use it in GitHub Desktop.  
  
    
      This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
      Learn more about bidirectional Unicode characters
    
  
  
    
  | #!/usr/bin/env python | |
| # -*- coding: utf-8 -*- | |
| import os | |
| import django | |
| django.setup() | |
| # Must come after django.setup or trigger "Apps aren't loaded yet" exception | |
| from django.contrib.auth.models import User # noqa | |
| username = os.environ.get('DJANGO_SU_USERNAME', 'root') | |
| password = os.environ.get('DJANGO_SU_PASSWORD', 'root') | |
| email = os.environ.get('DJANGO_SU_EMAIL', 'root@localhost') | |
| try: | |
| # if user exists allow password to be updated | |
| user = User.objects.get(username=username) | |
| user.set_password(password) | |
| user.is_superuser = True | |
| user.is_staff = True | |
| user.save() | |
| except User.DoesNotExist: | |
| # otherwise create from scratch | |
| User.objects.create_superuser( | |
| username, email, password | |
| ) | 
  
    Sign up for free
    to join this conversation on GitHub.
    Already have an account?
    Sign in to comment