|
| 1 | +import os |
| 2 | +import django |
| 3 | +import random |
| 4 | +import sys |
| 5 | +from faker import Faker |
| 6 | + |
| 7 | +sys.path.append(os.path.dirname(os.path.dirname(os.path.abspath(__file__)))) |
| 8 | + |
| 9 | +os.environ.setdefault('DJANGO_SETTINGS_MODULE', 'Videogames_project.settings') |
| 10 | +django.setup() |
| 11 | + |
| 12 | +from videogames_register.models import VideoGame, Genre, Developer, UserProfile, Review, Copy |
| 13 | +from django.contrib.auth.models import User |
| 14 | + |
| 15 | +fake = Faker() |
| 16 | + |
| 17 | +def seed(): |
| 18 | + |
| 19 | + Copy.objects.all().delete() |
| 20 | + Review.objects.all().delete() |
| 21 | + VideoGame.objects.all().delete() |
| 22 | + Developer.objects.all().delete() |
| 23 | + UserProfile.objects.all().delete() |
| 24 | + User.objects.exclude(is_superuser=True).delete() |
| 25 | + Genre.objects.all().delete() |
| 26 | + |
| 27 | + GENRE_NAMES = ['Action', 'Adventure', 'RPG', 'Shooter', 'Puzzle', 'Strategy', 'Sports'] |
| 28 | + for name in GENRE_NAMES: |
| 29 | + Genre.objects.get_or_create(title=name) |
| 30 | + |
| 31 | + GAME_TITLES = [ |
| 32 | + "Shadowblade", "Galactic Titans", "Mystic Quest", "Steel Reign", |
| 33 | + "Cyber Drift", "Knightfall Chronicles", "Inferno Squad", "Frostbound", |
| 34 | + "Echoes of Oblivion", "Nova Arena", "Crystal Rift", "Phantom Protocol", |
| 35 | + "Neon Shards", "Eternal Siege", "Dark Horizon", "Turbo Strikers", |
| 36 | + "Skyfall Bastion", "Quantum Rift", "Blood Circuit", "Ashen Crown" |
| 37 | + ] |
| 38 | + |
| 39 | + GAME_DESCRIPTIONS = [ |
| 40 | + "A fast-paced action game set in a dystopian future.", |
| 41 | + "Explore ancient ruins and uncover hidden secrets.", |
| 42 | + "Command your troops in a real-time strategy battlefield.", |
| 43 | + "Join the rebellion against the galactic empire.", |
| 44 | + "A fantasy RPG with immersive storytelling and rich lore.", |
| 45 | + "Drive high-tech vehicles in a neon cyberpunk city.", |
| 46 | + "Survive endless waves of enemies in post-apocalyptic arenas.", |
| 47 | + "Build and manage your own medieval kingdom.", |
| 48 | + "Compete in futuristic sports tournaments with deadly consequences.", |
| 49 | + "Navigate political intrigue and betrayal in a space federation.", |
| 50 | + "Hack into networks while avoiding elite AI defenders.", |
| 51 | + "Fly elite starfighters in tactical interstellar battles.", |
| 52 | + "Uncover the mystery behind vanishing cities.", |
| 53 | + "Combine magic and technology to restore a broken world.", |
| 54 | + "Control mythical creatures in turn-based combat.", |
| 55 | + "Battle rogue AIs in a derelict digital wasteland.", |
| 56 | + "Rescue colonies lost to alien infestations.", |
| 57 | + "Rebuild civilization after a massive solar storm.", |
| 58 | + "Explore underwater cities and defend against sea monsters.", |
| 59 | + "Join secret guilds and shape the fate of nations." |
| 60 | + ] |
| 61 | + |
| 62 | + for _ in range(5): |
| 63 | + Developer.objects.create( |
| 64 | + name=fake.company(), |
| 65 | + founded_year=random.randint(2000, 2025) |
| 66 | + ) |
| 67 | + |
| 68 | + all_genres = list(Genre.objects.all()) |
| 69 | + all_devs = list(Developer.objects.all()) |
| 70 | + # Create only curated games |
| 71 | + games = [] |
| 72 | + for i in range(len(GAME_TITLES)): |
| 73 | + game = VideoGame.objects.create( |
| 74 | + title=GAME_TITLES[i], |
| 75 | + description=GAME_DESCRIPTIONS[i], |
| 76 | + release_date=fake.date_between(start_date='-10y', end_date='today'), |
| 77 | + genre=random.choice(all_genres), |
| 78 | + ) |
| 79 | + games.append(game) |
| 80 | + |
| 81 | + |
| 82 | + for _ in range(5): |
| 83 | + user = User.objects.create_user( |
| 84 | + username=fake.user_name(), |
| 85 | + email=fake.email(), |
| 86 | + password="testpass123" |
| 87 | + ) |
| 88 | + UserProfile.objects.create( |
| 89 | + user=user, |
| 90 | + country=fake.country(), |
| 91 | + age=random.randint(18, 50) |
| 92 | + ) |
| 93 | + users = list(User.objects.all()) |
| 94 | + |
| 95 | + |
| 96 | + |
| 97 | + for i in range(len(GAME_TITLES)): |
| 98 | + VideoGame.objects.create( |
| 99 | + title=GAME_TITLES[i], |
| 100 | + description=GAME_DESCRIPTIONS[i], |
| 101 | + release_date=fake.date_between(start_date='-10y', end_date='today'), |
| 102 | + genre=random.choice(all_genres), |
| 103 | + |
| 104 | + ) |
| 105 | + |
| 106 | + for game in games: |
| 107 | + for _ in range(random.randint(1, 3)): |
| 108 | + Copy.objects.create( |
| 109 | + game=game, |
| 110 | + serial_number=fake.uuid4(), |
| 111 | + condition=random.choice(['New', 'Used', 'Mint']) |
| 112 | + ) |
| 113 | + |
| 114 | + for _ in range(30): |
| 115 | + Review.objects.create( |
| 116 | + user=random.choice(users), |
| 117 | + game=random.choice(games), |
| 118 | + rating=random.randint(1, 10), |
| 119 | + comment=fake.sentence() |
| 120 | + ) |
| 121 | + |
| 122 | + |
| 123 | + for game in games: |
| 124 | + for _ in range(random.randint(1, 3)): |
| 125 | + Copy.objects.create( |
| 126 | + game=game, |
| 127 | + serial_number=fake.uuid4(), |
| 128 | + condition=random.choice(['New', 'Used', 'Mint']) |
| 129 | + ) |
| 130 | + |
| 131 | + print("Done seeding data.") |
| 132 | + |
| 133 | +if __name__ == "__main__": |
| 134 | + seed() |
0 commit comments