Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

#83 Check for all the categories in the path one by one #85

Open
wants to merge 4 commits into
base: master
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
21 changes: 13 additions & 8 deletions categories/views.py
Original file line number Diff line number Diff line change
Expand Up @@ -20,15 +20,14 @@
def category_detail(request, path,
template_name='categories/category_detail.html', extra_context={}):
path_items = path.strip('/').split('/')
if len(path_items) >= 2:
category = get_object_or_404(Category,
slug__iexact=path_items[-1],
level=len(path_items) - 1,
parent__slug__iexact=path_items[-2])
else:
categories = []
parent = None
for slug in path_items:
category = get_object_or_404(Category,
slug__iexact=path_items[-1],
level=len(path_items) - 1)
slug__iexact=slug,
parent=parent)
categories.append(category)
parent = categories[-1]

templates = []
while path_items:
Expand All @@ -44,6 +43,11 @@ def category_detail(request, path,


def get_category_for_path(path, queryset=Category.objects.all()):
path_items = path.strip('/').split('/')
for slug in path_items:
queryset = queryset.filter(
slug__iexact=slug)
"""
path_items = path.strip('/').split('/')
if len(path_items) >= 2:
queryset = queryset.filter(
Expand All @@ -54,6 +58,7 @@ def get_category_for_path(path, queryset=Category.objects.all()):
queryset = queryset.filter(
slug__iexact=path_items[-1],
level=len(path_items) - 1)
"""
return queryset.get()


Expand Down