From 935547c44de0e1363c88832ff11c6a3f1d52c56d Mon Sep 17 00:00:00 2001 From: Laurent Date: Thu, 13 Feb 2025 12:33:47 +0100 Subject: [PATCH] Adds the last participation if the last created event was not find --- tournaments/models/custom_user.py | 9 +++++++++ 1 file changed, 9 insertions(+) diff --git a/tournaments/models/custom_user.py b/tournaments/models/custom_user.py index befa50d..c77bc62 100644 --- a/tournaments/models/custom_user.py +++ b/tournaments/models/custom_user.py @@ -1,4 +1,5 @@ from django.db import models +from django.apps import apps from django.contrib.auth.models import AbstractUser from . import club, enums import uuid @@ -63,4 +64,12 @@ class CustomUser(AbstractUser): latest_event = self.event_set.order_by('-creation_date').first() if latest_event and latest_event.club: return latest_event.club.name + if self.licence_id: + PlayerRegistration = apps.get_model('tournaments', 'PlayerRegistration') + player_registration = PlayerRegistration.objects.filter(licence_id=self.licence_id).order_by('team_registration__registration_date').first() + try: + return player_registration.team_registration.tournament.event.club.name + except AttributeError: + return None + return None