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>
This commit is contained in:
@@ -68,15 +68,21 @@ class Season(ClubScopedModel):
|
||||
end_date = models.DateField(_("end date"))
|
||||
|
||||
def __str__(self):
|
||||
return f"{self.start_date} - {self.end_date}"
|
||||
return self.name
|
||||
|
||||
class Meta:
|
||||
verbose_name = _("season")
|
||||
verbose_name_plural = _("seasons")
|
||||
|
||||
@property
|
||||
def name(self):
|
||||
"""Short label built from the start/end years, e.g. "25-26"."""
|
||||
return f"{self.start_date:%y}-{self.end_date:%y}"
|
||||
|
||||
@classmethod
|
||||
def get_current(cls, date: datetime.date | None = None):
|
||||
"""Return the current club's season covering ``date`` (today by default)."""
|
||||
if date is None:
|
||||
date = timezone.now().date()
|
||||
|
||||
|
||||
|
||||
return cls.objects.current_club().filter(start_date__lte=date, end_date__gte=date).first()
|
||||
|
||||
Reference in New Issue
Block a user