@@ -47,9 +47,11 @@ def should_autopick(self):
47
47
return self .autopick != self .Autopick .NONE
48
48
49
49
50
- class ActiveStatusManager (models .Manager ):
51
- def get_queryset (self ):
52
- return super ().get_queryset ().filter (status = self .model .Status .ACTIVE )
50
+ class PickerGroupingManager (models .Manager ):
51
+ def active (self ):
52
+ return self .filter (
53
+ status = self .model .Status .ACTIVE , leagues__is_active = True
54
+ ).prefetch_related ("leagues" , "members" )
53
55
54
56
55
57
class PickerGrouping (models .Model ):
@@ -67,8 +69,7 @@ class Status(models.TextChoices):
67
69
status = models .CharField (max_length = 4 , choices = Status .choices , default = Status .ACTIVE )
68
70
category = models .CharField (max_length = 3 , choices = Category .choices , default = Category .PRIVATE )
69
71
70
- objects = models .Manager ()
71
- active = ActiveStatusManager ()
72
+ objects = PickerGroupingManager ()
72
73
73
74
def __str__ (self ):
74
75
return self .name
@@ -89,15 +90,17 @@ def save(self, *args, **kws):
89
90
return super ().save (* args , ** kws )
90
91
91
92
92
- class ActiveMembershipManager (models .Manager ):
93
- def get_queryset (self ):
93
+ class MembershipManager (models .Manager ):
94
+ def active (self , ** kwargs ):
94
95
return (
95
- super ()
96
- .get_queryset ()
97
- .filter (status = self .model .Status .ACTIVE , group__status = PickerGrouping .Status .ACTIVE )
96
+ self .filter (
97
+ status = self .model .Status .ACTIVE ,
98
+ group__status = PickerGrouping .Status .ACTIVE ,
99
+ ** kwargs ,
100
+ )
98
101
.select_related ("group" )
99
102
.prefetch_related (
100
- models .Prefetch ("group__leagues" , queryset = sports .League .active . all ())
103
+ models .Prefetch ("group__leagues" , queryset = sports .League .objects . active ())
101
104
)
102
105
)
103
106
@@ -106,7 +109,7 @@ def for_user(self, user, league=None):
106
109
if league :
107
110
kwargs ["group__leagues" ] = league
108
111
109
- return self .filter (** kwargs )
112
+ return self .active (** kwargs )
110
113
111
114
112
115
class PickerMembership (models .Model ):
@@ -129,8 +132,7 @@ class Status(models.TextChoices):
129
132
status = models .CharField (max_length = 4 , choices = Status .choices , default = Status .ACTIVE )
130
133
autopick = models .CharField (max_length = 4 , choices = Autopick .choices , default = Autopick .RANDOM )
131
134
132
- objects = models .Manager ()
133
- active = ActiveMembershipManager ()
135
+ objects = MembershipManager ()
134
136
135
137
def __str__ (self ):
136
138
return f"{ self .user } @{ self .group } "
0 commit comments