diff --git a/InvenTree/part/api.py b/InvenTree/part/api.py index 9c4fdd6ba0..05f803f196 100644 --- a/InvenTree/part/api.py +++ b/InvenTree/part/api.py @@ -1051,6 +1051,24 @@ class PartList(generics.ListCreateAPIView): ] +class PartRelatedList(generics.ListCreateAPIView): + """ + API endpoint for accessing a list of PartRelated objects + """ + + queryset = PartRelated.objects.all() + serializer_class = part_serializers.PartRelationSerializer + + +class PartRelatedDetail(generics.RetrieveUpdateDestroyAPIView): + """ + API endpoint for accessing detail view of a PartRelated object + """ + + queryset = PartRelated.objects.all() + serializer_class = part_serializers.PartRelationSerializer + + class PartParameterTemplateList(generics.ListCreateAPIView): """ API endpoint for accessing a list of PartParameterTemplate objects. @@ -1475,6 +1493,12 @@ part_api_urls = [ url(r'^.*$', PartInternalPriceList.as_view(), name='api-part-internal-price-list'), ])), + # Base URL for PartRelated API endpoints + url(r'^related/', include([ + url(r'^(?P\d+)/', PartRelatedDetail.as_view(), name='api-part-related-detail'), + url(r'^.*$', PartRelatedList.as_view(), name='api-part-related-list'), + ])), + # Base URL for PartParameter API endpoints url(r'^parameter/', include([ url(r'^template/$', PartParameterTemplateList.as_view(), name='api-part-parameter-template-list'), diff --git a/InvenTree/part/serializers.py b/InvenTree/part/serializers.py index 49460c83a6..c7c89834fb 100644 --- a/InvenTree/part/serializers.py +++ b/InvenTree/part/serializers.py @@ -25,7 +25,7 @@ from InvenTree.status_codes import BuildStatus, PurchaseOrderStatus from stock.models import StockItem from .models import (BomItem, BomItemSubstitute, - Part, PartAttachment, PartCategory, + Part, PartAttachment, PartCategory, PartRelated, PartParameter, PartParameterTemplate, PartSellPriceBreak, PartStar, PartTestTemplate, PartCategoryParameterTemplate, PartInternalPriceBreak) @@ -225,6 +225,20 @@ class PartBriefSerializer(InvenTreeModelSerializer): ] +class PartRelationSerializer(InvenTreeModelSerializer): + """ + Serializer for a PartRelated model + """ + + class Meta: + model = PartRelated + fields = [ + 'pk', + 'part_1', + 'part_2', + ] + + class PartSerializer(InvenTreeModelSerializer): """ Serializer for complete detail information of a part. Used when displaying all details of a single component.