diff --git a/InvenTree/part/models.py b/InvenTree/part/models.py index dfe5161edc..c65fe7500e 100644 --- a/InvenTree/part/models.py +++ b/InvenTree/part/models.py @@ -9,10 +9,20 @@ class PartCategory(models.Model): def __str__(self): if self.parent: - return str(self.parent) + "/" + self.name + return "/".join([p.name for p in self.path]) + "/" + self.name else: return self.name + # Return the parent path of this category + @property + def path(self): + parent_path = [] + + if self.parent: + parent_path = self.parent.path + [self.parent] + + return parent_path + class Part(models.Model): name = models.CharField(max_length=100) description = models.CharField(max_length=250, blank=True) @@ -25,4 +35,7 @@ class Part(models.Model): ipn = self.IPN, name = self.name) else: - return self.name \ No newline at end of file + return self.name + + + \ No newline at end of file diff --git a/InvenTree/part/templates/part/category.html b/InvenTree/part/templates/part/category.html new file mode 100644 index 0000000000..db96243793 --- /dev/null +++ b/InvenTree/part/templates/part/category.html @@ -0,0 +1,17 @@ +

Category: {{ category.name }}

+ +

Path: {{ category }}

+ +
+Path
+ +{# Construct the category path #} +{% for path_item in category.path %} +{{path_item.name}}/ +{% endfor %} + +
Parts:
+ +{% for part in category.part_set.all %} +{{part.name}}
+{% endfor %} diff --git a/InvenTree/part/templates/part/detail.html b/InvenTree/part/templates/part/detail.html new file mode 100644 index 0000000000..8793e7ce13 --- /dev/null +++ b/InvenTree/part/templates/part/detail.html @@ -0,0 +1 @@ +{{part}} \ No newline at end of file diff --git a/InvenTree/part/urls.py b/InvenTree/part/urls.py index 59e5d723c9..8223b87b5d 100644 --- a/InvenTree/part/urls.py +++ b/InvenTree/part/urls.py @@ -3,5 +3,10 @@ from django.conf.urls import url from . import views urlpatterns = [ + # Display part detail + url(r'^(?P[0-9]+)/$', views.partdetail, name='detail'), + + # Display a part category + url(r'^category/(?P[0-9]+)/$', views.category, name='category'), url(r'^$', views.index, name='index') ] \ No newline at end of file diff --git a/InvenTree/part/views.py b/InvenTree/part/views.py index 197afdb84c..3750612d1b 100644 --- a/InvenTree/part/views.py +++ b/InvenTree/part/views.py @@ -1,5 +1,22 @@ -from django.shortcuts import render +from django.shortcuts import render, get_object_or_404 from django.http import HttpResponse +from .models import PartCategory, Part + def index(request): return HttpResponse("Hello world. This is the parts page") + +def partdetail(request, part_id): + + part = get_object_or_404(Part, pk=part_id) + + return render(request, 'part/detail.html', + {'part': part}) + +def category(request, category_id): + + # Find the category + cat = get_object_or_404(PartCategory, pk=category_id) + + return render(request, 'part/category.html', + {'category': cat}) \ No newline at end of file