Commits

John Shaffer  committed 072d994

Simplify category views.

  • Participants
  • Parent commits bd21784

Comments (0)

Files changed (1)

File satchmo/shop/views/category.py

 def root(request, slug):
     #Display the category page if we're not dealing with a child category
     try:
-        category = Category.objects.filter(slug=slug)[0]
-    except IndexError:
+        category = Category.objects.get(slug=slug)
+    except Category.DoesNotExist:
         return bad_or_missing(request, _('The category you have requested does not exist.'))
 
     child_categories = category.get_all_children()
 def children(request, slug_parent, slug):
     #Display the category if it is a child
     try:
-        parent = Category.objects.filter(slug=slug_parent)[0]
-    except IndexError:
-        return bad_or_missing(request, _('The category you have requested does not exist.'))
-    try:
-        category = parent.child.filter(slug=slug)[0]
-    except IndexError:
+        parent = Category.objects.get(slug=slug_parent)
+        category = parent.child.get(slug=slug)
+    except Category.DoesNotExist:
         return bad_or_missing(request, _('The category you have requested does not exist.'))
 
     child_categories = category.get_all_children()