InvenTree/InvenTree/part/api.py

58 lines
1.1 KiB
Python
Raw Normal View History

# -*- coding: utf-8 -*-
from __future__ import unicode_literals
2018-04-23 11:18:35 +00:00
from django_filters.rest_framework import DjangoFilterBackend
from rest_framework import filters
from rest_framework import generics, permissions
from django.conf.urls import url
from .models import Part, PartCategory
from .serializers import PartSerializer
from InvenTree.views import TreeSerializer
class PartCategoryTree(TreeSerializer):
title = "Parts"
model = PartCategory
class PartList(generics.ListCreateAPIView):
queryset = Part.objects.all()
serializer_class = PartSerializer
2018-04-15 15:02:17 +00:00
permission_classes = [
permissions.IsAuthenticatedOrReadOnly,
]
filter_backends = [
DjangoFilterBackend,
filters.SearchFilter,
filters.OrderingFilter,
]
filter_fields = [
2018-04-23 11:18:35 +00:00
'category',
]
ordering_fields = [
'name',
]
ordering = 'name'
2018-04-23 11:18:35 +00:00
search_fields = [
'name',
'description',
]
part_api_urls = [
url(r'^tree/?', PartCategoryTree.as_view(), name='api-part-tree'),
url(r'^.*$', PartList.as_view(), name='api-part-list'),
]