Files
RosterChief/clubmanager/base.py
Bernard Siebens 3914765f90 feat(tenancy): add Season current-season lookup and year name
Complete the Season model:

- name property renders the start/end years as a "YY-YY" label (e.g.
  "25-26") via strftime %y, and __str__ now returns it.
- get_current(date) returns the active club's season covering the given
  date (today by default), inclusive of both boundaries, scoped through
  the tenant queryset so it never crosses clubs.

Rename the tenant queryset's current() to current_club() for clarity and
update callers/tests. Cover the new behaviour; tenancy modules stay at
100%.

Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
2026-07-12 15:38:06 +02:00

43 lines
1.0 KiB
Python

import uuid
from typing import TYPE_CHECKING
from django.db import models
from club.tenancy import require_current_club
if TYPE_CHECKING:
from club.models import Club
class TenantQuerySet(models.QuerySet):
def for_club(self, club: Club):
return self.filter(club=club)
def current_club(self):
return self.filter(club=require_current_club())
class UUIDModel(models.Model):
"""Abstract base class giving every model a UUID primary key"""
id = models.UUIDField(primary_key=True, default=uuid.uuid4, editable=False)
class Meta:
abstract = True
class ClubScopedModel(UUIDModel):
"""Abstract base for entities owned by a single club (tenant root)."""
club = models.ForeignKey("club.Club", on_delete=models.CASCADE, related_name="%(class)ss")
objects = TenantQuerySet.as_manager()
class Meta:
abstract = True
def save(self, *args, **kwargs):
if self.club_id is None:
self.club = require_current_club()
super().save(*args, **kwargs)