-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathseed_script.py
More file actions
72 lines (58 loc) · 2.31 KB
/
Copy pathseed_script.py
File metadata and controls
72 lines (58 loc) · 2.31 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
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
import os
import django
import random
from datetime import datetime, timedelta
# Setup Django Environment
os.environ.setdefault('DJANGO_SETTINGS_MODULE', 'ticket_booking_system.settings')
django.setup()
from django.contrib.auth.models import User
from bookings.models import Movie, Show, Booking
def run_seed():
print("🌱 Starting Database Seed...")
# 1. Clear existing data
Booking.objects.all().delete()
Show.objects.all().delete()
Movie.objects.all().delete()
User.objects.filter(username__in=['john_doe', 'jane_smith']).delete()
# 2. Create Users
user1 = User.objects.create_user('john_doe', 'john@example.com', 'password123')
user2 = User.objects.create_user('jane_smith', 'jane@example.com', 'password123')
print(f"✅ Created 2 Users: {user1.username}, {user2.username}")
# 3. Create Movies
movies_data = [
("Inception", 148),
("The Matrix", 136),
("Interstellar", 169),
("The Dark Knight", 152)
]
movies = []
for title, duration in movies_data:
m = Movie.objects.create(title=title, duration_minutes=duration)
movies.append(m)
print(f"✅ Created {len(movies)} Movies")
# 4. Create Shows
screens = ["Screen A", "Screen B", "IMAX"]
base_time = datetime.now()
shows = []
for movie in movies:
for i in range(3): # 3 shows per movie
show_time = base_time + timedelta(days=random.randint(0, 3), hours=random.randint(10, 22))
s = Show.objects.create(
movie=movie,
screen_name=random.choice(screens),
date_time=show_time,
total_seats=50 # Small capacity for easier testing
)
shows.append(s)
print(f"✅ Created {len(shows)} Shows")
# 5. Create some initial bookings
print("... Simulating bookings")
Booking.objects.create(user=user1, show=shows[0], seat_number=1, status='booked')
Booking.objects.create(user=user2, show=shows[0], seat_number=2, status='booked')
Booking.objects.create(user=user1, show=shows[1], seat_number=5, status='booked')
print("🎉 Seeding Complete!")
print("\nTest Credentials:")
print("Username: john_doe / Password: password123")
print("Username: jane_smith / Password: password123")
if __name__ == '__main__':
run_seed()