from django.db import models from django.core.validators import FileExtensionValidator class Wrestler(models.Model): GROUP_CHOICES = [ ('kids', 'Kids'), ('youth', 'Youth'), ('adults', 'Adults'), ] first_name = models.CharField(max_length=100) last_name = models.CharField(max_length=100) club = models.ForeignKey('clubs.Club', on_delete=models.CASCADE, related_name='wrestlers') group = models.CharField(max_length=20, choices=GROUP_CHOICES) date_of_birth = models.DateField(null=True, blank=True) gender = models.CharField(max_length=10, choices=[('m', 'Male'), ('f', 'Female')], default='m') weight_category = models.CharField(max_length=50, blank=True) weight_kg = models.DecimalField(max_digits=5, decimal_places=2, null=True, blank=True) license_number = models.CharField(max_length=100, blank=True) license_expiry = models.DateField(null=True, blank=True) photo = models.ImageField( upload_to='wrestlers/photos/', null=True, blank=True, validators=[FileExtensionValidator(allowed_extensions=['jpg', 'jpeg', 'png', 'webp'])] ) license_scan = models.FileField( upload_to='wrestlers/licenses/', null=True, blank=True, validators=[FileExtensionValidator(allowed_extensions=['jpg', 'jpeg', 'png', 'pdf', 'webp'])] ) is_active = models.BooleanField(default=True) notes = models.TextField(blank=True) created_at = models.DateTimeField(auto_now_add=True) updated_at = models.DateTimeField(auto_now=True) class Meta: ordering = ['last_name', 'first_name'] indexes = [ models.Index(fields=['club', 'group']), models.Index(fields=['is_active']), ] def __str__(self): return f"{self.first_name} {self.last_name}" def calculate_age(self): if self.date_of_birth: from datetime import date today = date.today() return today.year - self.date_of_birth.year - ( (today.month, today.day) < (self.date_of_birth.month, self.date_of_birth.day) ) return None