Indicate docker config in readme and auto create admin user in docker
All checks were successful
Docker / build (push) Successful in 10s
All checks were successful
Docker / build (push) Successful in 10s
This commit is contained in:
parent
4bc1afa0cb
commit
9994403925
3 changed files with 99 additions and 0 deletions
32
photologue/management/commands/create_default_admin.py
Normal file
32
photologue/management/commands/create_default_admin.py
Normal file
|
|
@ -0,0 +1,32 @@
|
|||
from django.contrib.auth import get_user_model
|
||||
from django.core.management.base import BaseCommand
|
||||
|
||||
|
||||
class Command(BaseCommand):
|
||||
help = "Create default admin user (admin@localhost / admin) if it does not exist"
|
||||
|
||||
def handle(self, *args, **kwargs):
|
||||
User = get_user_model()
|
||||
email = "admin@localhost"
|
||||
username = "admin"
|
||||
password = "admin"
|
||||
|
||||
if User.objects.filter(username=username).exists():
|
||||
self.stdout.write("Default admin already exists, skipping.")
|
||||
return
|
||||
|
||||
user = User.objects.create_superuser(username=username, email=email, password=password)
|
||||
|
||||
# Mark the email as verified via allauth
|
||||
try:
|
||||
from allauth.account.models import EmailAddress
|
||||
EmailAddress.objects.create(
|
||||
user=user,
|
||||
email=email,
|
||||
primary=True,
|
||||
verified=True,
|
||||
)
|
||||
except Exception as e:
|
||||
self.stderr.write(f"Could not create allauth EmailAddress: {e}")
|
||||
|
||||
self.stdout.write(f"Default admin created: {username} / {password}")
|
||||
Loading…
Add table
Add a link
Reference in a new issue