Skip to content

Commit

Permalink
Added create super user script and change main.yml
Browse files Browse the repository at this point in the history
  • Loading branch information
FredMagas committed Aug 8, 2024
1 parent 377f8f6 commit 952b19e
Show file tree
Hide file tree
Showing 2 changed files with 36 additions and 0 deletions.
19 changes: 19 additions & 0 deletions .github/workflows/main.yml
Original file line number Diff line number Diff line change
Expand Up @@ -58,6 +58,25 @@ jobs:
run: |
source venv/bin/activate
python manage.py collectstatic --noinput
- name: Create superuser
env:
DATABASE_URL: ${{ secrets.DATABASE_URL }}
SECRET_KEY: ${{ secrets.SECRET_KEY }}
EMAIL_HOST: ${{ secrets.EMAIL_HOST }}
EMAIL_PORT: ${{ secrets.EMAIL_PORT }}
EMAIL_HOST_USER: ${{ secrets.EMAIL_HOST_USER }}
EMAIL_HOST_PASSWORD: ${{ secrets.EMAIL_HOST_PASSWORD }}
DEFAULT_FROM_EMAIL: ${{ secrets.DEFAULT_FROM_EMAIL }}
CLOUDINARY_CLOUD_NAME: ${{ secrets.CLOUDINARY_CLOUD_NAME }}
CLOUDINARY_API_KEY: ${{ secrets.CLOUDINARY_API_KEY }}
CLOUDINARY_API_SECRET: ${{ secrets.CLOUDINARY_API_SECRET }}
DJANGO_SUPERUSER_USERNAME: ${{ secrets.DJANGO_SUPERUSER_USERNAME }}
DJANGO_SUPERUSER_EMAIL: ${{ secrets.DJANGO_SUPERUSER_EMAIL }}
DJANGO_SUPERUSER_PASSWORD: ${{ secrets.DJANGO_SUPERUSER_PASSWORD }}
run: |
source venv/bin/activate
python manage.py createsuperuser
- name: Trigger Render Deploy
env:
Expand Down
17 changes: 17 additions & 0 deletions fredmagaweb/managements/commands/createsuperuser.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
from django.core.management.base import BaseCommand
from django.contrib.auth.models import User
from decouple import config

class Command(BaseCommand):
help = 'Create a superuser'

def handle(self, *args, **kwargs):
username = config('DJANGO_SUPERUSER_USERNAME')
email = config('DJANGO_SUPERUSER_EMAIL')
password = config('DJANGO_SUPERUSER_PASSWORD')

if User.objects.filter(username=username).exists():
self.stdout.write(self.style.WARNING('Superuser already exists.'))
else:
User.objects.create_superuser(username=username, email=email, password=password)
self.stdout.write(self.style.SUCCESS('Superuser created successfully.'))

0 comments on commit 952b19e

Please sign in to comment.