Skip to content

Commit 4377c6d

Browse files
committed
Remove get_queryset() and add new class variable .
1 parent 6e1d38d commit 4377c6d

File tree

1 file changed

+7
-7
lines changed

1 file changed

+7
-7
lines changed

pydis_site/apps/api/viewsets/bot/off_topic_channel_name.py

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -57,18 +57,18 @@ class OffTopicChannelNameViewSet(ModelViewSet):
5757

5858
lookup_field = 'name'
5959
serializer_class = OffTopicChannelNameSerializer
60+
queryset = OffTopicChannelName.objects.all()
6061

6162
def get_object(self) -> OffTopicChannelName:
6263
"""
6364
Returns the OffTopicChannelName entry for this request, if it exists.
6465
6566
If it doesn't, a HTTP 404 is returned by way of throwing an exception.
6667
"""
67-
queryset = self.get_queryset()
6868
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)
7070

71-
def get_queryset(self, **kwargs) -> QuerySet:
71+
def get_queryset(self) -> QuerySet:
7272
"""Returns a queryset that covers the entire OffTopicChannelName table."""
7373
return OffTopicChannelName.objects.all()
7474

@@ -108,13 +108,13 @@ def list(self, request: Request, *args, **kwargs) -> Response:
108108
'random_items': ["Must be a positive integer."]
109109
})
110110

111-
queryset = self.get_queryset().order_by('used', '?')[:random_count]
111+
queryset = self.queryset.order_by('used', '?')[:random_count]
112112

113113
# When any name is used in our listing then this means we reached end of round
114114
# and we need to reset all other names `used` to False
115115
if any(offtopic_name.used for offtopic_name in queryset):
116116
# These names that we just got have to be excluded from updating used to False
117-
self.get_queryset().update(
117+
self.queryset.update(
118118
used=Case(
119119
When(
120120
name__in=(offtopic_name.name for offtopic_name in queryset),
@@ -125,7 +125,7 @@ def list(self, request: Request, *args, **kwargs) -> Response:
125125
)
126126
else:
127127
# Otherwise mark selected names `used` to True
128-
self.get_queryset().filter(
128+
self.queryset.filter(
129129
name__in=(offtopic_name.name for offtopic_name in queryset)
130130
).update(used=True)
131131

@@ -137,6 +137,6 @@ def list(self, request: Request, *args, **kwargs) -> Response:
137137
if active_param := request.query_params.get("active"):
138138
params["active"] = active_param.lower() == "true"
139139

140-
queryset = self.get_queryset().filter(**params)
140+
queryset = self.queryset.filter(**params)
141141
serialized = self.serializer_class(queryset, many=True)
142142
return Response(serialized.data)

0 commit comments

Comments
 (0)