Last active
September 23, 2020 05:34
-
-
Save gemcave/7fd28a308b5d1d8e2356ce12d5c1f922 to your computer and use it in GitHub Desktop.
django redirect + filter
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
... | |
path('/filter/', views.FilterView.as_view(), name="type_filter"), | |
path('/filter/<page_slug>', views.FilterView.as_view(), name="type_filter_with_slug"), |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
def get_queryset(self): | |
if self.kwargs.get('page_slug'): | |
slug = self.kwargs.get('page_slug') | |
query_string = { | |
'green': 'street=2', | |
'russian': 'type=1', | |
}.get(slug) | |
base_url = reverse('type_filter') | |
url = '{}?{}'.format(base_url, query_string) | |
return redirect(url) | |
if (self.request.GET.getlist("type") or self.request.GET.getlist("street"): | |
// Поиск по базе данных используя полученные значения из query словаря | |
return queryset |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment