mirror of
https://github.com/inventree/InvenTree.git
synced 2025-04-30 04:26:44 +00:00
Further API improvements
This commit is contained in:
parent
6f9bf45e22
commit
2299cd0700
@ -157,6 +157,7 @@ class PartParameterManager(models.Manager):
|
|||||||
|
|
||||||
return super(PartParameterManager, self).create(*args, **kwargs)
|
return super(PartParameterManager, self).create(*args, **kwargs)
|
||||||
|
|
||||||
|
|
||||||
class PartParameter(models.Model):
|
class PartParameter(models.Model):
|
||||||
""" PartParameter is associated with a single part
|
""" PartParameter is associated with a single part
|
||||||
"""
|
"""
|
||||||
|
@ -55,6 +55,6 @@ urlpatterns = [
|
|||||||
# Part templates
|
# Part templates
|
||||||
url(r'^templates/', include(parttemplatepatterns)),
|
url(r'^templates/', include(parttemplatepatterns)),
|
||||||
|
|
||||||
# List of all parts
|
# List parts with optional filters
|
||||||
url(r'^$', views.PartList.as_view())
|
url(r'^\?*[^/]*/?$', views.PartList.as_view()),
|
||||||
]
|
]
|
||||||
|
@ -1,3 +1,5 @@
|
|||||||
|
# import django_filters
|
||||||
|
|
||||||
from rest_framework import generics, permissions
|
from rest_framework import generics, permissions
|
||||||
|
|
||||||
from .models import PartCategory, Part, PartParameter, PartParameterTemplate
|
from .models import PartCategory, Part, PartParameter, PartParameterTemplate
|
||||||
@ -46,9 +48,33 @@ class PartParamDetail(generics.RetrieveUpdateDestroyAPIView):
|
|||||||
permission_classes = (permissions.IsAuthenticatedOrReadOnly,)
|
permission_classes = (permissions.IsAuthenticatedOrReadOnly,)
|
||||||
|
|
||||||
|
|
||||||
class PartList(generics.ListCreateAPIView):
|
"""
|
||||||
|
class PartFilter(django_filters.rest_framework.FilterSet):
|
||||||
|
min_stock = django_filters.NumberFilter(name="stock", lookup_expr="gte")
|
||||||
|
max_stock = django_filters.NumberFilter(name="stock", lookup_expr="lte")
|
||||||
|
|
||||||
|
class Meta:
|
||||||
|
model = Part
|
||||||
|
fields = ['stock']
|
||||||
|
"""
|
||||||
|
|
||||||
|
|
||||||
|
class PartList(generics.ListCreateAPIView):
|
||||||
|
""" Display a list of parts, with optional filters
|
||||||
|
Filters are specified in the url, e.g.
|
||||||
|
/part/?category=127
|
||||||
|
/part/?min_stock=100
|
||||||
|
"""
|
||||||
|
|
||||||
|
def get_queryset(self):
|
||||||
|
parts = Part.objects.all()
|
||||||
|
|
||||||
|
cat_id = self.request.query_params.get('category', None)
|
||||||
|
if cat_id:
|
||||||
|
parts = parts.filter(category=cat_id)
|
||||||
|
|
||||||
|
return parts
|
||||||
|
|
||||||
queryset = Part.objects.all()
|
|
||||||
serializer_class = PartSerializer
|
serializer_class = PartSerializer
|
||||||
permission_classes = (permissions.IsAuthenticatedOrReadOnly,)
|
permission_classes = (permissions.IsAuthenticatedOrReadOnly,)
|
||||||
|
|
||||||
|
@ -15,11 +15,8 @@ projectpartpatterns = [
|
|||||||
# Detail of a single project part
|
# Detail of a single project part
|
||||||
url(r'^(?P<pk>[0-9]+)/$', views.ProjectPartDetail.as_view()),
|
url(r'^(?P<pk>[0-9]+)/$', views.ProjectPartDetail.as_view()),
|
||||||
|
|
||||||
# Parts associated with a project
|
# List project parts, with optional filters
|
||||||
url(r'^\?[^/]*/$', views.ProjectPartsList.as_view()),
|
url(r'^\?*[^/]*/?$', views.ProjectPartsList.as_view()),
|
||||||
|
|
||||||
# All project parts
|
|
||||||
url(r'^$', views.ProjectPartsList.as_view()),
|
|
||||||
]
|
]
|
||||||
|
|
||||||
projectcategorypatterns = [
|
projectcategorypatterns = [
|
||||||
|
Loading…
x
Reference in New Issue
Block a user