Files
WrestleDesk/backend/wrestlers/models.py
T
Andrej Spielmann 3fefc550fe Initial commit: WrestleDesk full project
- Django backend with DRF (clubs, wrestlers, trainers, exercises, templates, trainings, homework, locations, leistungstest)
- Next.js 16 frontend with React, Shadcn UI, Tailwind
- JWT authentication
- Full CRUD for all entities
- Calendar view for trainings
- Homework management system
- Leistungstest tracking
2026-03-26 13:24:57 +01:00

59 lines
2.1 KiB
Python

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