Skip to content

Instantly share code, notes, and snippets.

@filipgorczynski
Last active February 22, 2018 07:44
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save filipgorczynski/84e8438972582e355e95e89f7a340c53 to your computer and use it in GitHub Desktop.
Save filipgorczynski/84e8438972582e355e95e89f7a340c53 to your computer and use it in GitHub Desktop.
class HelloWorldViewSet(viewsets.ModelViewSet)
def get_queryset(self):
qs = super().get_queryset()
# Dobieramy się do parametrów żądania
query = self.request.query_params.get('q')
stripped_query = query.strip() if isinstance(query, str) else None
if stripped_query == '':
# Interesująca nas linijka
return qs.none()
# dodatkowe filtry, pomijane gdy stripped_query będzie None
# otrzymamy wszystkie wyniki bez filtrowania
if stripped_query:
# qs = qs.filter()
...
return qs
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment