mirror of
https://github.com/inventree/InvenTree
synced 2024-08-30 18:33:04 +00:00
Add part-list API
- Deleted some old serializers - Simply list of parts - Search by name / description - Orderable by name
This commit is contained in:
parent
f1a5b3c1ca
commit
86a9b36c99
@ -1,20 +1,18 @@
|
||||
from django.conf.urls import url, include
|
||||
from django.contrib import admin
|
||||
|
||||
from part.urls import part_api_urls, part_cat_api_urls
|
||||
from part.urls import bom_api_urls
|
||||
from company.urls import company_urls
|
||||
|
||||
from part.urls import part_urls
|
||||
from part.urls import supplier_part_urls
|
||||
|
||||
from stock.urls import stock_api_urls, stock_api_loc_urls
|
||||
from stock.urls import stock_urls
|
||||
|
||||
# from supplier.urls import supplier_api_urls, supplier_api_part_urls
|
||||
from company.urls import company_urls
|
||||
from company.api import company_api_urls
|
||||
|
||||
from build.urls import build_urls
|
||||
|
||||
from part.api import part_api_urls
|
||||
from company.api import company_api_urls
|
||||
|
||||
from django.conf import settings
|
||||
from django.conf.urls.static import static
|
||||
|
||||
@ -28,6 +26,7 @@ from users.urls import user_urls
|
||||
admin.site.site_header = "InvenTree Admin"
|
||||
|
||||
apipatterns = [
|
||||
url(r'^part/', include(part_api_urls)),
|
||||
url(r'^company/', include(company_api_urls)),
|
||||
|
||||
|
||||
|
@ -1,15 +1,16 @@
|
||||
# -*- coding: utf-8 -*-
|
||||
from __future__ import unicode_literals
|
||||
|
||||
from django_filters.rest_framework import FilterSet, DjangoFilterBackend
|
||||
from rest_framework import filters
|
||||
|
||||
from rest_framework import generics, permissions
|
||||
|
||||
from django.conf.urls import url
|
||||
|
||||
from .models import Company
|
||||
from .serializers import CompanySerializer
|
||||
|
||||
|
||||
|
||||
|
||||
class CompanyList(generics.ListCreateAPIView):
|
||||
|
||||
serializer_class = CompanySerializer
|
||||
@ -25,14 +26,14 @@ class CompanyList(generics.ListCreateAPIView):
|
||||
]
|
||||
|
||||
filter_fields = [
|
||||
'name',
|
||||
'is_customer',
|
||||
'is_supplier',
|
||||
'name',
|
||||
'is_customer',
|
||||
'is_supplier',
|
||||
]
|
||||
|
||||
search_fields = [
|
||||
'name',
|
||||
'description',
|
||||
'name',
|
||||
'description',
|
||||
]
|
||||
|
||||
ordering_fields = [
|
||||
|
@ -1,202 +1,42 @@
|
||||
from .serializers import PartSerializer
|
||||
from .serializers import PartCategorySerializer
|
||||
from .serializers import BomItemSerializer
|
||||
|
||||
from rest_framework import generics, permissions
|
||||
# -*- coding: utf-8 -*-
|
||||
from __future__ import unicode_literals
|
||||
|
||||
from django_filters.rest_framework import FilterSet, DjangoFilterBackend
|
||||
from rest_framework import filters
|
||||
from rest_framework import generics, permissions
|
||||
|
||||
from .models import PartCategory, Part, BomItem
|
||||
from django.conf.urls import url
|
||||
|
||||
from InvenTree.models import FilterChildren
|
||||
|
||||
|
||||
class PartDetail(generics.RetrieveUpdateDestroyAPIView):
|
||||
"""
|
||||
|
||||
get:
|
||||
Return detail on a single Part
|
||||
|
||||
post:
|
||||
Update data for a single Part
|
||||
|
||||
delete:
|
||||
Remove a part from the database
|
||||
|
||||
"""
|
||||
queryset = Part.objects.all()
|
||||
serializer_class = PartSerializer
|
||||
permission_classes = (permissions.IsAuthenticatedOrReadOnly,)
|
||||
|
||||
|
||||
"""
|
||||
class PartParamFilter(FilterSet):
|
||||
|
||||
class Meta:
|
||||
model = PartParameter
|
||||
fields = ['part']
|
||||
|
||||
class PartParamList(generics.ListCreateAPIView):
|
||||
"
|
||||
|
||||
get:
|
||||
Return a list of all part parameters (with optional filters)
|
||||
|
||||
post:
|
||||
Create a new part parameter
|
||||
""
|
||||
|
||||
queryset = PartParameter.objects.all()
|
||||
serializer_class = PartParameterSerializer
|
||||
permission_classes = (permissions.IsAuthenticatedOrReadOnly,)
|
||||
filter_backends = (DjangoFilterBackend,)
|
||||
filter_class = PartParamFilter
|
||||
|
||||
|
||||
class PartParamDetail(generics.RetrieveUpdateDestroyAPIView):
|
||||
""
|
||||
|
||||
get:
|
||||
Detail view of a single PartParameter
|
||||
|
||||
post:
|
||||
Update data for a PartParameter
|
||||
|
||||
delete:
|
||||
Remove a PartParameter from the database
|
||||
|
||||
"
|
||||
|
||||
queryset = PartParameter.objects.all()
|
||||
serializer_class = PartParameterSerializer
|
||||
permission_classes = (permissions.IsAuthenticatedOrReadOnly,)
|
||||
"""
|
||||
|
||||
|
||||
class PartFilter(FilterSet):
|
||||
|
||||
class Meta:
|
||||
model = Part
|
||||
fields = ['category']
|
||||
from .models import Part
|
||||
from .serializers import PartSerializer
|
||||
|
||||
|
||||
class PartList(generics.ListCreateAPIView):
|
||||
"""
|
||||
|
||||
get:
|
||||
List of Parts, with optional filters
|
||||
|
||||
post:
|
||||
Create a new Part
|
||||
"""
|
||||
|
||||
queryset = Part.objects.all()
|
||||
serializer_class = PartSerializer
|
||||
permission_classes = (permissions.IsAuthenticatedOrReadOnly,)
|
||||
filter_backends = (DjangoFilterBackend,)
|
||||
filter_class = PartFilter
|
||||
|
||||
permission_classes = [
|
||||
permissions.IsAuthenticatedOrReadOnly,
|
||||
]
|
||||
|
||||
class PartCategoryDetail(generics.RetrieveUpdateDestroyAPIView):
|
||||
"""
|
||||
filter_backends = [
|
||||
DjangoFilterBackend,
|
||||
filters.SearchFilter,
|
||||
filters.OrderingFilter,
|
||||
]
|
||||
|
||||
get:
|
||||
Return information on a single PartCategory
|
||||
filter_fields = [
|
||||
|
||||
post:
|
||||
Update a PartCategory
|
||||
]
|
||||
|
||||
delete:
|
||||
Remove a PartCategory
|
||||
ordering_fields = [
|
||||
'name',
|
||||
]
|
||||
|
||||
"""
|
||||
queryset = PartCategory.objects.all()
|
||||
serializer_class = PartCategorySerializer
|
||||
permission_classes = (permissions.IsAuthenticatedOrReadOnly,)
|
||||
ordering = 'name'
|
||||
|
||||
part_api_urls = [
|
||||
|
||||
class PartCategoryList(generics.ListCreateAPIView):
|
||||
"""
|
||||
|
||||
get:
|
||||
Return a list of all categories
|
||||
(with optional filters)
|
||||
|
||||
post:
|
||||
Create a new PartCategory
|
||||
"""
|
||||
|
||||
def get_queryset(self):
|
||||
params = self.request.query_params
|
||||
|
||||
categories = PartCategory.objects.all()
|
||||
|
||||
categories = FilterChildren(categories, params.get('parent', None))
|
||||
|
||||
return categories
|
||||
|
||||
queryset = PartCategory.objects.filter(parent=None)
|
||||
serializer_class = PartCategorySerializer
|
||||
permission_classes = (permissions.IsAuthenticatedOrReadOnly,)
|
||||
|
||||
|
||||
"""
|
||||
class PartTemplateDetail(generics.RetrieveUpdateDestroyAPIView):
|
||||
""
|
||||
|
||||
get:
|
||||
Return detail on a single PartParameterTemplate object
|
||||
|
||||
post:
|
||||
Update a PartParameterTemplate object
|
||||
|
||||
delete:
|
||||
Remove a PartParameterTemplate object
|
||||
|
||||
""
|
||||
|
||||
queryset = PartParameterTemplate.objects.all()
|
||||
serializer_class = PartTemplateSerializer
|
||||
permission_classes = (permissions.IsAuthenticatedOrReadOnly,)
|
||||
|
||||
|
||||
class PartTemplateList(generics.ListCreateAPIView):
|
||||
""
|
||||
|
||||
get:
|
||||
Return a list of all PartParameterTemplate objects
|
||||
(with optional query filters)
|
||||
|
||||
post:
|
||||
Create a new PartParameterTemplate object
|
||||
|
||||
""
|
||||
|
||||
queryset = PartParameterTemplate.objects.all()
|
||||
serializer_class = PartTemplateSerializer
|
||||
permission_classes = (permissions.IsAuthenticatedOrReadOnly,)
|
||||
|
||||
"""
|
||||
|
||||
|
||||
class BomItemDetail(generics.RetrieveUpdateDestroyAPIView):
|
||||
|
||||
queryset = BomItem.objects.all()
|
||||
serializer_class = BomItemSerializer
|
||||
permission_classes = (permissions.IsAuthenticatedOrReadOnly,)
|
||||
|
||||
|
||||
class BomItemFilter(FilterSet):
|
||||
|
||||
class Meta:
|
||||
model = BomItem
|
||||
fields = ['part', 'sub_part']
|
||||
|
||||
|
||||
class BomItemList(generics.ListCreateAPIView):
|
||||
|
||||
queryset = BomItem.objects.all()
|
||||
serializer_class = BomItemSerializer
|
||||
permission_classes = (permissions.IsAuthenticatedOrReadOnly,)
|
||||
filter_backends = (DjangoFilterBackend,)
|
||||
filter_class = BomItemFilter
|
||||
url(r'^.*$', PartList.as_view(), name='api-part-list'),
|
||||
]
|
||||
|
@ -1,33 +1,6 @@
|
||||
from rest_framework import serializers
|
||||
|
||||
from .models import Part, PartCategory
|
||||
from .models import BomItem
|
||||
|
||||
|
||||
class BomItemSerializer(serializers.ModelSerializer):
|
||||
|
||||
class Meta:
|
||||
model = BomItem
|
||||
fields = ('url',
|
||||
'part',
|
||||
'sub_part',
|
||||
'quantity')
|
||||
|
||||
|
||||
"""
|
||||
class PartParameterSerializer(serializers.HyperlinkedModelSerializer):
|
||||
" Serializer for a PartParameter
|
||||
"
|
||||
|
||||
class Meta:
|
||||
model = PartParameter
|
||||
fields = ('url',
|
||||
'part',
|
||||
'template',
|
||||
'name',
|
||||
'value',
|
||||
'units')
|
||||
"""
|
||||
from .models import Part
|
||||
|
||||
|
||||
class PartSerializer(serializers.ModelSerializer):
|
||||
@ -37,35 +10,18 @@ class PartSerializer(serializers.ModelSerializer):
|
||||
|
||||
class Meta:
|
||||
model = Part
|
||||
fields = ('url',
|
||||
'name',
|
||||
'IPN',
|
||||
'description',
|
||||
'category',
|
||||
'stock',
|
||||
'units',
|
||||
'trackable',
|
||||
)
|
||||
|
||||
|
||||
class PartCategorySerializer(serializers.HyperlinkedModelSerializer):
|
||||
|
||||
class Meta:
|
||||
model = PartCategory
|
||||
fields = ('url',
|
||||
'name',
|
||||
'description',
|
||||
'parent',
|
||||
'pathstring')
|
||||
|
||||
|
||||
"""
|
||||
class PartTemplateSerializer(serializers.HyperlinkedModelSerializer):
|
||||
|
||||
class Meta:
|
||||
model = PartParameterTemplate
|
||||
fields = ('url',
|
||||
'name',
|
||||
'units',
|
||||
'format')
|
||||
"""
|
||||
fields = [
|
||||
'url', # Link to the part detail page
|
||||
'name',
|
||||
'IPN',
|
||||
'URL', # Link to an external URL (optional)
|
||||
'description',
|
||||
'category',
|
||||
'total_stock',
|
||||
'available_stock',
|
||||
'units',
|
||||
'trackable',
|
||||
'buildable',
|
||||
'trackable',
|
||||
'salable',
|
||||
]
|
||||
|
@ -2,7 +2,6 @@ from django.conf.urls import url, include
|
||||
from django.views.generic.base import RedirectView
|
||||
|
||||
from . import views
|
||||
from . import api
|
||||
|
||||
supplier_part_detail_urls = [
|
||||
url(r'edit/?', views.SupplierPartEdit.as_view(), name='supplier-part-edit'),
|
||||
@ -17,38 +16,6 @@ supplier_part_urls = [
|
||||
url(r'^(?P<pk>\d+)/', include(supplier_part_detail_urls)),
|
||||
]
|
||||
|
||||
# URL list for part category API
|
||||
part_cat_api_urls = [
|
||||
|
||||
# Part category detail
|
||||
url(r'^(?P<pk>[0-9]+)/?$', api.PartCategoryDetail.as_view(), name='partcategory-detail'),
|
||||
|
||||
# List of top-level categories
|
||||
url(r'^\?*.*/?$', api.PartCategoryList.as_view()),
|
||||
url(r'^$', api.PartCategoryList.as_view())
|
||||
]
|
||||
|
||||
|
||||
# URL list for part API
|
||||
part_api_urls = [
|
||||
|
||||
# Individual part
|
||||
url(r'^(?P<pk>[0-9]+)/?$', api.PartDetail.as_view(), name='part-detail'),
|
||||
|
||||
# List parts with optional filters
|
||||
url(r'^\?.*/?$', api.PartList.as_view()),
|
||||
url(r'^$', api.PartList.as_view()),
|
||||
]
|
||||
|
||||
bom_api_urls = [
|
||||
# Bom Item detail
|
||||
url(r'^(?P<pk>[0-9]+)/?$', api.BomItemDetail.as_view(), name='bomitem-detail'),
|
||||
|
||||
# List of top-level categories
|
||||
url(r'^\?*.*/?$', api.BomItemList.as_view()),
|
||||
url(r'^$', api.BomItemList.as_view())
|
||||
]
|
||||
|
||||
part_detail_urls = [
|
||||
url(r'^edit/?', views.PartEdit.as_view(), name='part-edit'),
|
||||
url(r'^delete/?', views.PartDelete.as_view(), name='part-delete'),
|
||||
|
Loading…
Reference in New Issue
Block a user