fix LB sorting

online_registration
Raz 1 year ago
parent c45b44fbf8
commit dc683b0762
  1. 13
      tournaments/models/round.py

@ -67,11 +67,22 @@ class Round(models.Model):
matches.sort(key=lambda m: m.index)
# Recursively fetch matches from child rounds
for child_round in self.children.all():
# Sort children by depth in ascending order (deeper rounds last)
sorted_children = sorted(self.children.all(), key=lambda child: child.get_depth())
for child_round in sorted_children:
matches.extend(child_round.get_matches_recursive(hide_empty_matches))
return matches
def get_depth(self):
depth = 0
current_round = self
while current_round.parent:
depth += 1
current_round = current_round.parent
return depth
def root_round(self):
if self.parent is None:
return self

Loading…
Cancel
Save