mirror of
https://github.com/pacnpal/thrillwiki_django_no_react.git
synced 2025-12-27 10:07:05 -05:00
feat: Add blog, media, and support apps, implement ride credits and image API, and remove toplist feature.
This commit is contained in:
32
backend/ensure_admin.py
Normal file
32
backend/ensure_admin.py
Normal file
@@ -0,0 +1,32 @@
|
||||
import os
|
||||
import sys
|
||||
import django
|
||||
|
||||
sys.path.append(os.path.join(os.path.dirname(__file__)))
|
||||
os.environ.setdefault("DJANGO_SETTINGS_MODULE", "thrillwiki.settings")
|
||||
django.setup()
|
||||
|
||||
from django.contrib.auth import get_user_model
|
||||
User = get_user_model()
|
||||
|
||||
def ensure_admin():
|
||||
username = "admin"
|
||||
email = "admin@example.com"
|
||||
password = "adminpassword"
|
||||
|
||||
if not User.objects.filter(username=username).exists():
|
||||
print(f"Creating superuser {username}...")
|
||||
User.objects.create_superuser(username=username, email=email, password=password, role="ADMIN")
|
||||
print("Superuser created.")
|
||||
else:
|
||||
print(f"Superuser {username} already exists.")
|
||||
u = User.objects.get(username=username)
|
||||
if not u.is_staff or not u.is_superuser or u.role != 'ADMIN':
|
||||
u.is_staff = True
|
||||
u.is_superuser = True
|
||||
u.role = 'ADMIN'
|
||||
u.save()
|
||||
print("Updated existing user to ADMIN/Superuser.")
|
||||
|
||||
if __name__ == "__main__":
|
||||
ensure_admin()
|
||||
Reference in New Issue
Block a user