Skip to content

Commit

Permalink
Allow filtering of authors endpoint by name
Browse files Browse the repository at this point in the history
  • Loading branch information
jessamynsmith committed Apr 20, 2022
1 parent 502e084 commit 7192da3
Showing 1 changed file with 7 additions and 1 deletion.
8 changes: 7 additions & 1 deletion quotations/views.py
Original file line number Diff line number Diff line change
Expand Up @@ -66,7 +66,13 @@ def get_queryset(self):

class QuotationsByAuthorViewSet(viewsets.ReadOnlyModelViewSet):
serializer_class = serializers.AuthorQuotationsSerializer
queryset = quotation_models.Author.objects.all()

def get_queryset(self):
queryset = quotation_models.Author.objects.all()
name = self.request.query_params.get('name')
if name is not None:
queryset = queryset.filter(name__icontains=name)
return queryset


def redirect_to_random(request):
Expand Down

0 comments on commit 7192da3

Please sign in to comment.