Expose stock items labels to the API

This commit is contained in:
Oliver Walters 2021-01-08 22:19:52 +11:00
parent 5666db6b7a
commit 446c744462
3 changed files with 71 additions and 0 deletions

View File

@ -28,6 +28,7 @@ from company.api import company_api_urls
from stock.api import stock_api_urls
from build.api import build_api_urls
from order.api import order_api_urls
from label.api import label_api_urls
from django.conf import settings
from django.conf.urls.static import static
@ -58,6 +59,7 @@ apipatterns = [
url(r'^stock/', include(stock_api_urls)),
url(r'^build/', include(build_api_urls)),
url(r'^order/', include(order_api_urls)),
url(r'^label/', include(label_api_urls)),
# User URLs
url(r'^user/', include(user_urls)),

43
InvenTree/label/api.py Normal file
View File

@ -0,0 +1,43 @@
# -*- coding: utf-8 -*-
from __future__ import unicode_literals
from django.conf.urls import url, include
from django_filters.rest_framework import DjangoFilterBackend
from rest_framework import generics, filters
from .models import StockItemLabel
from .serializers import StockItemLabelSerializer
class StockItemLabelList(generics.ListAPIView):
"""
API endpoint for viewing list of StockItemLabel objects.
"""
queryset = StockItemLabel.objects.all()
serializer_class = StockItemLabelSerializer
filter_backends = [
DjangoFilterBackend,
filters.SearchFilter
]
filter_fields = [
'enabled',
]
search_fields = [
'name',
'description',
]
label_api_urls = [
# Stock item labels
url(r'stock/', include([
url(r'^.*$', StockItemLabelList.as_view(), name='api-stock-label-list'),
])),
]

View File

@ -0,0 +1,26 @@
# -*- coding: utf-8 -*-
from __future__ import unicode_literals
from InvenTree.serializers import InvenTreeModelSerializer
from InvenTree.serializers import InvenTreeAttachmentSerializerField
from .models import StockItemLabel
class StockItemLabelSerializer(InvenTreeModelSerializer):
"""
Serializes a StockItemLabel object.
"""
label = InvenTreeAttachmentSerializerField(required=True)
class Meta:
model = StockItemLabel
fields = [
'pk',
'name',
'description',
'label',
'filters',
'enabled',
]