inital checkin
This commit is contained in:
58
store/management/commands/create_test_packs.py
Normal file
58
store/management/commands/create_test_packs.py
Normal file
@@ -0,0 +1,58 @@
|
||||
from django.core.management.base import BaseCommand
|
||||
from store.models import Game, Set, Card, PackListing, VirtualPack
|
||||
import random
|
||||
|
||||
class Command(BaseCommand):
|
||||
help = 'Creates test packs for MTG, Lorcana, and Pokemon'
|
||||
|
||||
def handle(self, *args, **kwargs):
|
||||
games_data = [
|
||||
{'name': 'Magic: The Gathering', 'slug': 'mtg', 'pack_price': 4.99},
|
||||
{'name': 'Disney Lorcana', 'slug': 'lorcana', 'pack_price': 5.99},
|
||||
{'name': 'Pokémon', 'slug': 'pokemon', 'pack_price': 3.99},
|
||||
]
|
||||
|
||||
for game_info in games_data:
|
||||
# Lookup by slug since it's unique
|
||||
game, _ = Game.objects.get_or_create(
|
||||
slug=game_info['slug'],
|
||||
defaults={'name': game_info['name']}
|
||||
)
|
||||
|
||||
# Ensure at least one set exists
|
||||
set_obj, _ = Set.objects.get_or_create(
|
||||
game=game,
|
||||
name=f"{game.name} Base Set",
|
||||
defaults={'code': 'BASE'}
|
||||
)
|
||||
|
||||
# Ensure cards exist
|
||||
if not Card.objects.filter(set__game=game).exists():
|
||||
self.stdout.write(f"Creating dummy cards for {game.name}...")
|
||||
for i in range(20):
|
||||
Card.objects.create(
|
||||
set=set_obj,
|
||||
name=f"{game.name} Card {i+1}",
|
||||
rarity='Common',
|
||||
collector_number=str(i+1)
|
||||
)
|
||||
|
||||
# Create Pack Listing
|
||||
listing, _ = PackListing.objects.get_or_create(
|
||||
game=game,
|
||||
name=f"{game.name} Booster Pack",
|
||||
defaults={'price': game_info['pack_price']}
|
||||
)
|
||||
|
||||
self.stdout.write(f"Generating packs for {listing.name}...")
|
||||
|
||||
all_game_cards = list(Card.objects.filter(set__game=game))
|
||||
|
||||
# Create 10 packs
|
||||
for _ in range(10):
|
||||
pack = VirtualPack.objects.create(listing=listing)
|
||||
# Add 5 random cards
|
||||
pack_cards = random.sample(all_game_cards, min(len(all_game_cards), 5))
|
||||
pack.cards.set(pack_cards)
|
||||
|
||||
self.stdout.write(self.style.SUCCESS('Successfully created test packs'))
|
||||
Reference in New Issue
Block a user