@@ -57,18 +57,18 @@ class OffTopicChannelNameViewSet(ModelViewSet):
57
57
58
58
lookup_field = 'name'
59
59
serializer_class = OffTopicChannelNameSerializer
60
+ queryset = OffTopicChannelName .objects .all ()
60
61
61
62
def get_object (self ) -> OffTopicChannelName :
62
63
"""
63
64
Returns the OffTopicChannelName entry for this request, if it exists.
64
65
65
66
If it doesn't, a HTTP 404 is returned by way of throwing an exception.
66
67
"""
67
- queryset = self .get_queryset ()
68
68
name = self .kwargs [self .lookup_field ]
69
- return get_object_or_404 (queryset , name = name )
69
+ return get_object_or_404 (self . queryset , name = name )
70
70
71
- def get_queryset (self , ** kwargs ) -> QuerySet :
71
+ def get_queryset (self ) -> QuerySet :
72
72
"""Returns a queryset that covers the entire OffTopicChannelName table."""
73
73
return OffTopicChannelName .objects .all ()
74
74
@@ -108,13 +108,13 @@ def list(self, request: Request, *args, **kwargs) -> Response:
108
108
'random_items' : ["Must be a positive integer." ]
109
109
})
110
110
111
- queryset = self .get_queryset () .order_by ('used' , '?' )[:random_count ]
111
+ queryset = self .queryset .order_by ('used' , '?' )[:random_count ]
112
112
113
113
# When any name is used in our listing then this means we reached end of round
114
114
# and we need to reset all other names `used` to False
115
115
if any (offtopic_name .used for offtopic_name in queryset ):
116
116
# These names that we just got have to be excluded from updating used to False
117
- self .get_queryset () .update (
117
+ self .queryset .update (
118
118
used = Case (
119
119
When (
120
120
name__in = (offtopic_name .name for offtopic_name in queryset ),
@@ -125,7 +125,7 @@ def list(self, request: Request, *args, **kwargs) -> Response:
125
125
)
126
126
else :
127
127
# Otherwise mark selected names `used` to True
128
- self .get_queryset () .filter (
128
+ self .queryset .filter (
129
129
name__in = (offtopic_name .name for offtopic_name in queryset )
130
130
).update (used = True )
131
131
@@ -137,6 +137,6 @@ def list(self, request: Request, *args, **kwargs) -> Response:
137
137
if active_param := request .query_params .get ("active" ):
138
138
params ["active" ] = active_param .lower () == "true"
139
139
140
- queryset = self .get_queryset () .filter (** params )
140
+ queryset = self .queryset .filter (** params )
141
141
serialized = self .serializer_class (queryset , many = True )
142
142
return Response (serialized .data )
0 commit comments