mirror of
https://github.com/jazzband/django-categories.git
synced 2026-03-16 22:30:24 +00:00
Added a view that list items of specific model that are related to the current category.
This commit is contained in:
parent
0b201156e0
commit
c89c954001
1 changed files with 28 additions and 0 deletions
|
|
@ -77,3 +77,31 @@ if django.VERSION[0] >= 1 and django.VERSION[1] >= 3:
|
|||
names.extend(super(CategoryDetailView, self).get_template_names())
|
||||
return names
|
||||
|
||||
|
||||
class CategoryRelatedList(ListView):
|
||||
|
||||
path_field = 'category_path'
|
||||
|
||||
def get_queryset(self):
|
||||
queryset = super(CategoryRelatedList, self).get_queryset()
|
||||
category = get_category_for_path(self.kwargs['category_path'])
|
||||
return queryset.filter(category=category)
|
||||
|
||||
def get_template_names(self):
|
||||
names = []
|
||||
if hasattr(self.object_list, 'model'):
|
||||
opts = self.object_list.model._meta
|
||||
path_items = self.kwargs[self.path_field].strip('/').split('/')
|
||||
while path_items:
|
||||
names.append( '%s/category_%s_%s%s.html' % (opts.app_label,
|
||||
'_'.join(path_items),
|
||||
opts.object_name.lower(),
|
||||
self.template_name_suffix)
|
||||
)
|
||||
path_items.pop()
|
||||
names.append('%s/category_%s%s.html' % (opts.app_label,
|
||||
opts.object_name.lower(),
|
||||
self.template_name_suffix)
|
||||
)
|
||||
names.extend(super(CategoryRelatedList, self).get_template_names())
|
||||
return names
|
||||
Loading…
Reference in a new issue