Skip to content

Commit 73ff82b

Browse files
authored
udpated readme for examples according to new release v0.2.0 (#16)
1 parent e138e09 commit 73ff82b

File tree

1 file changed

+15
-14
lines changed

1 file changed

+15
-14
lines changed

README.md

Lines changed: 15 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ on incoming query params and their values. A beautiful python package voluptouos
88
---
99
**Installation**
1010

11-
1. Download `drf-url-filters` app package from this git repo or can be installed using python-pip like `pip install drf-url-filters`.
11+
1. Download `drf-url-filters` app package from this git repo or can be isnatlled using python-pip like `pip install drf-url-filters`.
1212

1313
2. Add `filters` in INSTALLED_APPS of settings.py file of django project.
1414

@@ -90,22 +90,23 @@ class PlayersViewSet(FiltersMixin, viewsets.ModelViewSet):
9090
query parameters in the URL.
9191
"""
9292
query_params = self.request.query_params
93-
queryset = Player.objects.prefetch_related(
94-
'teams' # use prefetch_related to minimize db hits.
95-
).all()
93+
url_params = self.kwargs
94+
95+
# get queryset_filters from FilterMixin
96+
queryset_filters = self.get_db_filters(url_params, query_params)
9697

9798
# This dict will hold filter kwargs to pass in to Django ORM calls.
98-
db_filters = {}
99+
db_filters = queryset_filters['db_filters']
99100

100-
# update filters dict with incoming query params and then pass as
101-
# **kwargs to queryset.filter()
102-
db_filters.update(
103-
self.get_queryset_filters(
104-
query_params
105-
)
106-
)
107-
return queryset.filter(**db_filters)
101+
# This dict will hold exclude kwargs to pass in to Django ORM calls.
102+
db_excludes = queryset_filters['db_excludes']
103+
104+
# fetch queryset from Players model
105+
queryset = Player.objects.prefetch_related(
106+
'teams' # use prefetch_related to minimize db hits.
107+
).all()
108108

109+
return queryset.filter(**db_filters).exclude(**db_excludes)
109110
```
110111

111112
With the use of `drf-url-filters` adding a new filter on a new column is as simple as adding a new key in the dict. Prohibitting a filter on particular column is same as removing a key value mapping from the `filter_mappings` dict.
@@ -117,7 +118,7 @@ Copyright (c) 2016 Manjit Kumar
117118
Read more about it in LICENSE file available in repo.
118119

119120
# Credits
120-
Special thanks to authors of [voluptouos](https://github.com/alecthomas/voluptuous) and friends [*](https://github.com/cdax) [**](https://github.com/SaurabhJha) who encourage people to contribute into open source community.
121+
Special thanks to authors of [voluptouos](https://github.com/alecthomas/voluptuous) and friends [saurabhjha](https://github.com/cdax) [cdax](https://github.com/SaurabhJha) who encourage people to contribute into open source community.
121122

122123
# Support
123124
Please [open an issue](https://github.com/manjitkumar/drf-url-filters/issues/new) for support.

0 commit comments

Comments
 (0)