mirror of
https://github.com/inventree/InvenTree.git
synced 2025-04-30 12:36:45 +00:00
API endpoint for accessing part star information
This commit is contained in:
parent
86b5b8d16e
commit
70f1097ea0
@ -12,12 +12,13 @@ from rest_framework import generics, permissions
|
|||||||
from django.db.models import Q
|
from django.db.models import Q
|
||||||
from django.conf.urls import url, include
|
from django.conf.urls import url, include
|
||||||
|
|
||||||
from .models import Part, PartCategory, BomItem
|
from .models import Part, PartCategory, BomItem, PartStar
|
||||||
from .models import SupplierPart, SupplierPriceBreak
|
from .models import SupplierPart, SupplierPriceBreak
|
||||||
|
|
||||||
from .serializers import PartSerializer, BomItemSerializer
|
from .serializers import PartSerializer, BomItemSerializer
|
||||||
from .serializers import SupplierPartSerializer, SupplierPriceBreakSerializer
|
from .serializers import SupplierPartSerializer, SupplierPriceBreakSerializer
|
||||||
from .serializers import CategorySerializer
|
from .serializers import CategorySerializer
|
||||||
|
from .serializers import PartStarSerializer
|
||||||
|
|
||||||
from InvenTree.views import TreeSerializer
|
from InvenTree.views import TreeSerializer
|
||||||
|
|
||||||
@ -150,8 +151,37 @@ class PartList(generics.ListCreateAPIView):
|
|||||||
]
|
]
|
||||||
|
|
||||||
|
|
||||||
|
class PartStarList(generics.ListCreateAPIView):
|
||||||
|
""" API endpoint for accessing a list of PartStar objects.
|
||||||
|
|
||||||
|
- GET: Return list of PartStar objects
|
||||||
|
- POST: Create a new PartStar object
|
||||||
|
"""
|
||||||
|
|
||||||
|
queryset = PartStar.objects.all()
|
||||||
|
serializer_class = PartStarSerializer
|
||||||
|
|
||||||
|
permission_classes = [
|
||||||
|
permissions.IsAuthenticatedOrReadOnly,
|
||||||
|
]
|
||||||
|
|
||||||
|
filter_backends = [
|
||||||
|
DjangoFilterBackend,
|
||||||
|
filters.SearchFilter
|
||||||
|
]
|
||||||
|
|
||||||
|
filter_fields = [
|
||||||
|
'part',
|
||||||
|
'user',
|
||||||
|
]
|
||||||
|
|
||||||
|
search_fields = [
|
||||||
|
'partname'
|
||||||
|
]
|
||||||
|
|
||||||
|
|
||||||
class BomList(generics.ListCreateAPIView):
|
class BomList(generics.ListCreateAPIView):
|
||||||
""" API endpoing for accessing a list of BomItem objects
|
""" API endpoint for accessing a list of BomItem objects.
|
||||||
|
|
||||||
- GET: Return list of BomItem objects
|
- GET: Return list of BomItem objects
|
||||||
- POST: Create a new BomItem object
|
- POST: Create a new BomItem object
|
||||||
@ -267,12 +297,20 @@ supplier_part_api_urls = [
|
|||||||
url(r'^.*$', SupplierPartList.as_view(), name='api-part-supplier-list'),
|
url(r'^.*$', SupplierPartList.as_view(), name='api-part-supplier-list'),
|
||||||
]
|
]
|
||||||
|
|
||||||
|
part_star_api_urls = [
|
||||||
|
|
||||||
|
# Catchall
|
||||||
|
url(r'^.*$', PartStarList.as_view(), name='api-part-star-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'^category/', include(cat_api_urls)),
|
||||||
url(r'^supplier/', include(supplier_part_api_urls)),
|
url(r'^supplier/', include(supplier_part_api_urls)),
|
||||||
|
|
||||||
|
url(r'^star/', include(part_star_api_urls)),
|
||||||
|
|
||||||
url(r'^price-break/?', SupplierPriceBreakList.as_view(), name='api-part-supplier-price'),
|
url(r'^price-break/?', SupplierPriceBreakList.as_view(), name='api-part-supplier-price'),
|
||||||
|
|
||||||
url(r'^(?P<pk>\d+)/', PartDetail.as_view(), name='api-part-detail'),
|
url(r'^(?P<pk>\d+)/', PartDetail.as_view(), name='api-part-detail'),
|
||||||
|
@ -4,8 +4,10 @@ JSON serializers for Part app
|
|||||||
|
|
||||||
from rest_framework import serializers
|
from rest_framework import serializers
|
||||||
|
|
||||||
from .models import Part, PartCategory, BomItem
|
from .models import Part, PartStar, PartAttachment
|
||||||
from .models import SupplierPart, SupplierPriceBreak
|
from .models import SupplierPart, SupplierPriceBreak
|
||||||
|
from .models import PartCategory
|
||||||
|
from .models import BomItem
|
||||||
|
|
||||||
from InvenTree.serializers import InvenTreeModelSerializer
|
from InvenTree.serializers import InvenTreeModelSerializer
|
||||||
|
|
||||||
@ -75,6 +77,22 @@ class PartSerializer(serializers.ModelSerializer):
|
|||||||
]
|
]
|
||||||
|
|
||||||
|
|
||||||
|
class PartStarSerializer(InvenTreeModelSerializer):
|
||||||
|
""" Serializer for a PartStar object """
|
||||||
|
|
||||||
|
partname = serializers.CharField(source='part.name', read_only=True)
|
||||||
|
username = serializers.CharField(source='user.username', read_only=True)
|
||||||
|
|
||||||
|
class Meta:
|
||||||
|
model = PartStar
|
||||||
|
fields = [
|
||||||
|
'part',
|
||||||
|
'partname',
|
||||||
|
'user',
|
||||||
|
'username',
|
||||||
|
]
|
||||||
|
|
||||||
|
|
||||||
class BomItemSerializer(InvenTreeModelSerializer):
|
class BomItemSerializer(InvenTreeModelSerializer):
|
||||||
""" Serializer for BomItem object """
|
""" Serializer for BomItem object """
|
||||||
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user