2
0
mirror of https://github.com/inventree/InvenTree.git synced 2025-08-23 11:55:54 +00:00

Added REST framework

- /part/ URL is now a JSON api
This commit is contained in:
Oliver Walters
2017-03-28 22:12:02 +11:00
parent 457d72a3e4
commit 7bcea2f3ac
4 changed files with 51 additions and 29 deletions

View File

@@ -1,34 +1,30 @@
from django.shortcuts import render, get_object_or_404
from django.http import HttpResponse
from django.http import HttpResponse, Http404
from rest_framework import generics
from .models import PartCategory, Part
from .serializers import PartSerializer, PartCategorySerializer
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})
class PartDetail(generics.RetrieveAPIView):
def categoryList(request):
categories = PartCategory.objects.filter(parent = None)
return render(request, 'part/categorylist.html',
{'categories': categories
})
queryset = Part.objects.all()
serializer_class = PartSerializer
def category(request, category_id):
class PartList(generics.ListAPIView):
queryset = Part.objects.all()
serializer_class = PartSerializer
class PartCategoryDetail(generics.RetrieveAPIView):
# Find the category
cat = get_object_or_404(PartCategory, pk=category_id)
queryset = PartCategory.objects.all()
serializer_class = PartCategorySerializer
# Child categories
childs = PartCategory.objects.filter(parent = cat.pk)
return render(request, 'part/category.html',
{'category': cat,
'children': childs
})
class PartCategoryList(generics.ListAPIView):
queryset = PartCategory.objects.all()
serializer_class = PartCategorySerializer