thanthamky commited on
Commit
6ac1a95
·
verified ·
1 Parent(s): a2f9ee4

Create create_superuser.py

Browse files
Files changed (1) hide show
  1. create_superuser.py +20 -0
create_superuser.py ADDED
@@ -0,0 +1,20 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ # create_superuser.py
2
+ import os
3
+ import django
4
+
5
+ os.environ.setdefault('DJANGO_SETTINGS_MODULE', 'project.settings')
6
+ django.setup()
7
+
8
+ from django.contrib.auth import get_user_model
9
+
10
+ User = get_user_model()
11
+
12
+ username = 'admin'
13
+ email = 'admin@example.com'
14
+ password = 'admin'
15
+
16
+ if not User.objects.filter(username=username).exists():
17
+ print(f"Creating superuser {username}...")
18
+ User.objects.create_superuser(username=username, email=email, password=password)
19
+ else:
20
+ print(f"Superuser {username} already exists.")