inital checkin

This commit is contained in:
2026-01-20 05:22:38 -06:00
parent 9784e14c77
commit c43603bfb5
75 changed files with 4327 additions and 0 deletions

View File

View 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'))

View File

@@ -0,0 +1,139 @@
import random
import requests
from django.core.management.base import BaseCommand
from django.utils.text import slugify
from django.contrib.auth import get_user_model
from store.models import Game, Set, Card, CardListing
from faker import Faker
User = get_user_model()
fake = Faker()
class Command(BaseCommand):
help = 'Populate database with MTG data from Scryfall and fake data for other games'
def handle(self, *args, **options):
self.stdout.write('Starting database population...')
# Create Games
mtg, _ = Game.objects.get_or_create(name='Magic: The Gathering', slug='mtg')
pokemon, _ = Game.objects.get_or_create(name='Pokemon TCG', slug='pokemon')
lorcana, _ = Game.objects.get_or_create(name='Disney Lorcana', slug='lorcana')
# Populate MTG (Real Data)
self.populate_mtg(mtg)
# Populate Pokemon (Fake Data)
self.populate_fake_game(pokemon, 'Pokemon')
# Populate Lorcana (Fake Data)
self.populate_fake_game(lorcana, 'Lorcana')
# Create Superuser
if not User.objects.filter(username='admin').exists():
User.objects.create_superuser('admin', 'admin@example.com', 'admin')
self.stdout.write(self.style.SUCCESS('Created superuser: admin/admin'))
# Create Demo Users
self.create_demo_users()
self.stdout.write(self.style.SUCCESS('Database populated successfully!'))
def populate_mtg(self, game):
self.stdout.write('Fetching MTG data from Scryfall...')
# Get a few sets
sets_api = "https://api.scryfall.com/sets"
try:
resp = requests.get(sets_api).json()
# Pick top 3 recent expansion sets
target_sets = [s for s in resp['data'] if s['set_type'] == 'expansion'][:3]
for s_data in target_sets:
set_obj, created = Set.objects.get_or_create(
game=game,
name=s_data['name'],
code=s_data['code'],
defaults={'release_date': s_data.get('released_at')}
)
if created:
self.stdout.write(f"Created set: {set_obj.name}")
# Fetch cards for this set
cards_url = s_data['search_uri']
cards_resp = requests.get(cards_url).json()
for card_data in cards_resp.get('data', [])[:20]: # Limit to 20 cards per set to be fast
if 'image_uris' in card_data:
image = card_data['image_uris'].get('normal')
elif 'card_faces' in card_data and 'image_uris' in card_data['card_faces'][0]:
image = card_data['card_faces'][0]['image_uris'].get('normal')
else:
continue
card, _ = Card.objects.get_or_create(
set=set_obj,
name=card_data['name'],
defaults={
'rarity': card_data['rarity'].capitalize(),
'image_url': image,
'scryfall_id': card_data['id'],
'tcgplayer_id': card_data.get('tcgplayer_id'),
'collector_number': card_data['collector_number']
}
)
# Create Listings
self.create_listings_for_card(card)
except Exception as e:
self.stdout.write(self.style.ERROR(f"Failed to fetch MTG data: {e}"))
def populate_fake_game(self, game, prefix):
self.stdout.write(f'Generating data for {game.name}...')
for i in range(3): # 3 Sets
set_name = f"{prefix} Set {i+1}"
set_obj, _ = Set.objects.get_or_create(
game=game,
name=set_name,
code=f"{prefix[:3].upper()}{i+1}",
defaults={'release_date': fake.date_between(start_date='-2y', end_date='today')}
)
for j in range(15): # 15 Cards per set
card, _ = Card.objects.get_or_create(
set=set_obj,
name=f"{prefix} Monster {fake.word().capitalize()}",
defaults={
'rarity': random.choice(['Common', 'Uncommon', 'Rare', 'Ultra Rare']),
'image_url': f"https://placehold.co/400x600?text={prefix}+{j}",
'collector_number': str(j+1)
}
)
self.create_listings_for_card(card)
def create_listings_for_card(self, card):
# Create 1-5 listings per card with different conditions
for _ in range(random.randint(1, 4)):
condition = random.choice(['NM', 'LP', 'MP', 'HP'])
price = round(random.uniform(0.50, 100.00), 2)
CardListing.objects.create(
card=card,
condition=condition,
price=price,
quantity=random.randint(1, 20),
market_price=price, # Simplified
is_foil=random.choice([True, False])
)
def create_demo_users(self):
# Create a Pro user
if not User.objects.filter(username='prouser').exists():
u = User.objects.create_user('prouser', 'pro@example.com', 'password')
u.profile.is_pro = True
u.profile.save()
self.stdout.write("Created prouser/password")
# Create a Basic user
if not User.objects.filter(username='basicuser').exists():
User.objects.create_user('basicuser', 'basic@example.com', 'password')
self.stdout.write("Created basicuser/password")