from django.db import models from django.core.validators import FileExtensionValidator class Trainer(models.Model): 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='trainers') email = models.EmailField(blank=True) phone = models.CharField(max_length=50, blank=True) photo = models.ImageField( upload_to='trainers/photos/', null=True, blank=True, validators=[FileExtensionValidator(allowed_extensions=['jpg', 'jpeg', 'png', 'webp'])] ) is_active = models.BooleanField(default=True) created_at = models.DateTimeField(auto_now_add=True) updated_at = models.DateTimeField(auto_now=True) class Meta: ordering = ['last_name', 'first_name'] def __str__(self): return f"{self.first_name} {self.last_name}" # Note: Name uniqueness per club is not enforced at the database level. # If the same trainer works for multiple clubs, they would appear once per club. # If unique names per club are required, add: unique_together = ['first_name', 'last_name', 'club']