Added a categorylist page

Displays list of all top-level part categories
This commit is contained in:
Oliver Walters 2017-03-26 10:29:51 +11:00
parent 3f81046a26
commit b919418fb5
5 changed files with 23 additions and 4 deletions

View File

@ -16,10 +16,10 @@ class PartCategory(models.Model):
# Return the parent path of this category
@property
def path(self):
parent_path = []
if self.parent:
parent_path = self.parent.path + [self.parent]
return self.parent.path + [self.parent]
else:
return []
return parent_path

View File

@ -1,4 +1,5 @@
{# Construct the category path #}
<a href="../">Category</a>/
{% for path_item in category.path %}
<a href="../{{ path_item.pk }}">{{ path_item.name }}</a>/
{% endfor %}

View File

@ -0,0 +1,8 @@
Top Level Part Categories:
{% for category in categories %}
<br>
<a href="./{{ category.pk }}">{{ category.name }}<a/>
{% endfor %}

View File

@ -6,7 +6,10 @@ urlpatterns = [
# Display part detail
url(r'^(?P<part_id>[0-9]+)/$', views.partdetail, name='detail'),
# Display a part category
# Display a list of top-level categories
url(r'^category/$', views.categorylist, name='categorylist'),
# Display a single part category
url(r'^category/(?P<category_id>[0-9]+)/$', views.category, name='category'),
url(r'^$', views.index, name='index')
]

View File

@ -13,6 +13,13 @@ def partdetail(request, part_id):
return render(request, 'part/detail.html',
{'part': part})
def categorylist(request):
categories = PartCategory.objects.filter(parent = None)
return render(request, 'part/categorylist.html',
{'categories': categories
})
def category(request, category_id):
# Find the category