mirror of
https://github.com/inventree/InvenTree.git
synced 2025-04-30 04:26:44 +00:00
Part category API
This commit is contained in:
parent
83dd068fec
commit
7e4b0630b6
@ -5,13 +5,14 @@ from django_filters.rest_framework import DjangoFilterBackend
|
|||||||
from rest_framework import filters
|
from rest_framework import filters
|
||||||
from rest_framework import generics, permissions
|
from rest_framework import generics, permissions
|
||||||
|
|
||||||
from django.conf.urls import url
|
from django.conf.urls import url, include
|
||||||
|
|
||||||
from .models import Part, PartCategory, BomItem
|
from .models import Part, PartCategory, BomItem
|
||||||
from .models import SupplierPart
|
from .models import SupplierPart
|
||||||
|
|
||||||
from .serializers import PartSerializer, BomItemSerializer
|
from .serializers import PartSerializer, BomItemSerializer
|
||||||
from .serializers import SupplierPartSerializer
|
from .serializers import SupplierPartSerializer
|
||||||
|
from .serializers import CategorySerializer
|
||||||
|
|
||||||
from InvenTree.views import TreeSerializer
|
from InvenTree.views import TreeSerializer
|
||||||
|
|
||||||
@ -21,6 +22,36 @@ class PartCategoryTree(TreeSerializer):
|
|||||||
model = PartCategory
|
model = PartCategory
|
||||||
|
|
||||||
|
|
||||||
|
class CategoryList(generics.ListCreateAPIView):
|
||||||
|
queryset = PartCategory.objects.all()
|
||||||
|
serializer_class = CategorySerializer
|
||||||
|
|
||||||
|
permission_classes = [
|
||||||
|
permissions.IsAuthenticatedOrReadOnly,
|
||||||
|
]
|
||||||
|
|
||||||
|
filter_backends = [
|
||||||
|
DjangoFilterBackend,
|
||||||
|
#filters.SearchFilter,
|
||||||
|
filters.OrderingFilter,
|
||||||
|
]
|
||||||
|
|
||||||
|
filter_fields = [
|
||||||
|
'parent',
|
||||||
|
]
|
||||||
|
|
||||||
|
ordering_fields = [
|
||||||
|
'name',
|
||||||
|
]
|
||||||
|
|
||||||
|
ordering = 'name'
|
||||||
|
|
||||||
|
search_fields = [
|
||||||
|
'name',
|
||||||
|
'description',
|
||||||
|
]
|
||||||
|
|
||||||
|
|
||||||
class PartList(generics.ListCreateAPIView):
|
class PartList(generics.ListCreateAPIView):
|
||||||
|
|
||||||
queryset = Part.objects.all()
|
queryset = Part.objects.all()
|
||||||
@ -93,11 +124,17 @@ class SupplierPartList(generics.ListAPIView):
|
|||||||
'supplier'
|
'supplier'
|
||||||
]
|
]
|
||||||
|
|
||||||
|
cat_api_urls = [
|
||||||
|
|
||||||
|
url(r'^$', CategoryList.as_view(), name='api-part-category-list'),
|
||||||
|
]
|
||||||
|
|
||||||
part_api_urls = [
|
part_api_urls = [
|
||||||
|
|
||||||
url(r'^tree/?', PartCategoryTree.as_view(), name='api-part-tree'),
|
url(r'^tree/?', PartCategoryTree.as_view(), name='api-part-tree'),
|
||||||
|
|
||||||
|
url(r'^category/', include(cat_api_urls)),
|
||||||
|
|
||||||
url(r'^supplier/?', SupplierPartList.as_view(), name='api-part-supplier-list'),
|
url(r'^supplier/?', SupplierPartList.as_view(), name='api-part-supplier-list'),
|
||||||
url(r'^bom/?', BomList.as_view(), name='api-bom-list'),
|
url(r'^bom/?', BomList.as_view(), name='api-bom-list'),
|
||||||
url(r'^.*$', PartList.as_view(), name='api-part-list'),
|
url(r'^.*$', PartList.as_view(), name='api-part-list'),
|
||||||
|
@ -5,7 +5,7 @@ from .models import SupplierPart
|
|||||||
|
|
||||||
from company.serializers import CompanyBriefSerializer
|
from company.serializers import CompanyBriefSerializer
|
||||||
|
|
||||||
class CategoryBriefSerializer(serializers.ModelSerializer):
|
class CategorySerializer(serializers.ModelSerializer):
|
||||||
|
|
||||||
url = serializers.CharField(source='get_absolute_url', read_only=True)
|
url = serializers.CharField(source='get_absolute_url', read_only=True)
|
||||||
|
|
||||||
@ -17,6 +17,7 @@ class CategoryBriefSerializer(serializers.ModelSerializer):
|
|||||||
'description',
|
'description',
|
||||||
'pathstring',
|
'pathstring',
|
||||||
'url',
|
'url',
|
||||||
|
'parent',
|
||||||
]
|
]
|
||||||
|
|
||||||
|
|
||||||
@ -40,7 +41,7 @@ class PartSerializer(serializers.ModelSerializer):
|
|||||||
"""
|
"""
|
||||||
|
|
||||||
url = serializers.CharField(source='get_absolute_url', read_only=True)
|
url = serializers.CharField(source='get_absolute_url', read_only=True)
|
||||||
category = CategoryBriefSerializer(many=False, read_only=True)
|
category = CategorySerializer(many=False, read_only=True)
|
||||||
|
|
||||||
class Meta:
|
class Meta:
|
||||||
model = Part
|
model = Part
|
||||||
|
@ -16,6 +16,12 @@ function inventreeGet(url, filters={}) {
|
|||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Return list of parts with optional filters
|
||||||
function getParts(filters={}) {
|
function getParts(filters={}) {
|
||||||
return inventreeGet('/api/part/', filters);
|
return inventreeGet('/api/part/', filters);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Return list of part categories with optional filters
|
||||||
|
function getPartCategories(filters={}) {
|
||||||
|
return inventreeGet('/api/part/category/', filters);
|
||||||
|
}
|
@ -210,4 +210,6 @@
|
|||||||
|
|
||||||
getParts();
|
getParts();
|
||||||
|
|
||||||
|
getPartCategories({parent: 2});
|
||||||
|
|
||||||
{% endblock %}
|
{% endblock %}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user