Skip to content

Commit

Permalink
Remove empty categories from /items2
Browse files Browse the repository at this point in the history
  • Loading branch information
alexsierro committed Oct 16, 2024
1 parent 4b01d3b commit 6dae67a
Showing 1 changed file with 4 additions and 1 deletion.
5 changes: 4 additions & 1 deletion legacy/views.py
Original file line number Diff line number Diff line change
Expand Up @@ -127,7 +127,10 @@ def fill_category(request, category, list):

sub_categories = ResourceCategory.objects.filter(parent=category)
for subcategory in sub_categories:
fill_category(request, subcategory, category_items)
# do not include empty subcategories
if (Resource.objects.filter(category=subcategory).exclude(widget=None).exists()
or ResourceCategory.objects.filter(parent=subcategory).exists()):
fill_category(request, subcategory, category_items)

if category: # avoid resources without category to be mapped with root category
resources = Resource.objects.filter(category=category).exclude(widget=None)
Expand Down

0 comments on commit 6dae67a

Please sign in to comment.