-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathcreate_users.py
More file actions
46 lines (36 loc) · 1.57 KB
/
Copy pathcreate_users.py
File metadata and controls
46 lines (36 loc) · 1.57 KB
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
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
import os
import django
os.environ.setdefault('DJANGO_SETTINGS_MODULE', 'attendance_management_system.settings')
django.setup()
from django.contrib.auth import get_user_model
from attendance_management_system.models import Teacher, Student, Batch
User = get_user_model()
print("Creating users...")
# 1. Admin
if not User.objects.filter(username='admin').exists():
User.objects.create_superuser('admin', 'admin@example.com', 'admin')
print("✅ Superuser 'admin' created (password: admin)")
else:
print("ℹ️ Superuser 'admin' already exists.")
# 2. Faculty
if not User.objects.filter(username='faculty').exists():
faculty_user = User.objects.create_user('faculty', 'faculty@example.com', '123')
faculty_user.is_teacher = True
faculty_user.save()
Teacher.objects.create(user=faculty_user)
print("✅ Teacher 'faculty' created (password: 123)")
else:
print("ℹ️ User 'faculty' already exists.")
# 3. Student – ensure a default batch exists (Batch has only name + year, no section)
batch = Batch.objects.filter(name='B.Tech CSE').first()
if not batch:
batch = Batch.objects.create(name='B.Tech CSE', year=2024)
if not User.objects.filter(username='student1').exists():
student_user = User.objects.create_user('student1', 'student1@example.com', '123')
student_user.is_student = True
student_user.save()
Student.objects.create(user=student_user, batch=batch, roll_number='CS101')
print("✅ Student 'student1' created (password: 123)")
else:
print("ℹ️ User 'student1' already exists.")
print("\n✨ User setup complete!")