37 lines
1.5 KiB
Python
37 lines
1.5 KiB
Python
from django.db import models
|
|
from django.conf import settings
|
|
import urllib.parse
|
|
|
|
class Event(models.Model):
|
|
title = models.CharField(max_length=255)
|
|
description = models.TextField(blank=True)
|
|
start_time = models.DateTimeField()
|
|
end_time = models.DateTimeField(null=True, blank=True)
|
|
location_address = models.CharField(max_length=255)
|
|
maps_shortlink = models.URLField(blank=True, editable=False)
|
|
team = models.ForeignKey('clubs.Team', on_delete=models.CASCADE, related_name='events')
|
|
|
|
def save(self, *args, **kwargs):
|
|
if self.location_address and not self.maps_shortlink:
|
|
self.maps_shortlink = f"https://www.google.com/maps/search/?api=1&query={urllib.parse.quote(self.location_address)}"
|
|
super().save(*args, **kwargs)
|
|
|
|
def __str__(self):
|
|
return self.title
|
|
|
|
class Training(Event):
|
|
pass
|
|
|
|
class Game(Event):
|
|
opponent = models.CharField(max_length=255)
|
|
meeting_minutes_before_game = models.PositiveIntegerField(default=60)
|
|
season = models.CharField(max_length=255, blank=True)
|
|
min_players = models.PositiveIntegerField(default=9)
|
|
|
|
class GameResult(models.Model):
|
|
game = models.OneToOneField(Game, on_delete=models.CASCADE, related_name='result')
|
|
# A simple way to store inning results as a string. A more complex solution could use a JSONField or separate Inning model.
|
|
inning_results = models.CharField(max_length=255, help_text="Comma-separated scores per inning, e.g., '1-0,0-2,3-1'")
|
|
|
|
def __str__(self):
|
|
return f"Result for {self.game}" |