2017-03-25 23:06:00 +00:00
|
|
|
from django.shortcuts import render, get_object_or_404
|
2017-03-25 12:07:43 +00:00
|
|
|
from django.http import HttpResponse
|
|
|
|
|
2017-03-25 23:06:00 +00:00
|
|
|
from .models import PartCategory, Part
|
|
|
|
|
2017-03-25 12:07:43 +00:00
|
|
|
def index(request):
|
|
|
|
return HttpResponse("Hello world. This is the parts page")
|
2017-03-25 23:06:00 +00:00
|
|
|
|
2017-03-27 11:05:35 +00:00
|
|
|
def partDetail(request, part_id):
|
2017-03-25 23:06:00 +00:00
|
|
|
|
|
|
|
part = get_object_or_404(Part, pk=part_id)
|
|
|
|
|
|
|
|
return render(request, 'part/detail.html',
|
|
|
|
{'part': part})
|
|
|
|
|
2017-03-27 11:05:35 +00:00
|
|
|
def categoryList(request):
|
2017-03-25 23:29:51 +00:00
|
|
|
categories = PartCategory.objects.filter(parent = None)
|
|
|
|
|
|
|
|
return render(request, 'part/categorylist.html',
|
|
|
|
{'categories': categories
|
|
|
|
})
|
|
|
|
|
2017-03-25 23:06:00 +00:00
|
|
|
def category(request, category_id):
|
|
|
|
|
|
|
|
# Find the category
|
|
|
|
cat = get_object_or_404(PartCategory, pk=category_id)
|
|
|
|
|
2017-03-25 23:23:22 +00:00
|
|
|
# Child categories
|
|
|
|
childs = PartCategory.objects.filter(parent = cat.pk)
|
|
|
|
|
2017-03-25 23:06:00 +00:00
|
|
|
return render(request, 'part/category.html',
|
2017-03-25 23:23:22 +00:00
|
|
|
{'category': cat,
|
|
|
|
'children': childs
|
|
|
|
})
|