-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathcreate_admin.py
More file actions
26 lines (23 loc) · 803 Bytes
/
create_admin.py
File metadata and controls
26 lines (23 loc) · 803 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
import os
import django
# Set up Django environment
os.environ.setdefault('DJANGO_SETTINGS_MODULE', 'amc_tracker.settings')
django.setup()
# Import User model
from django.contrib.auth.models import User
# Create or update admin user
try:
# Check if admin user exists
if User.objects.filter(username='admin').exists():
admin = User.objects.get(username='admin')
admin.set_password('Root@1987')
admin.is_staff = True
admin.is_superuser = True
admin.save()
print("Admin user updated with password: Root@1987")
else:
# Create new admin user
User.objects.create_superuser('admin', 'admin@example.com', 'Root@1987')
print("Admin user created with password: Root@1987")
except Exception as e:
print(f"Error: {str(e)}")