mirror of
https://github.com/inventree/InvenTree
synced 2024-08-30 18:33:04 +00:00
Merge pull request #121 from SchrodingersGat/category-display
Category display
This commit is contained in:
commit
73b7c178d4
@ -3,7 +3,6 @@ dist: xenial
|
||||
language: python
|
||||
python:
|
||||
- 3.5
|
||||
- 3.6
|
||||
|
||||
addons:
|
||||
apt-packages:
|
||||
|
@ -5,7 +5,9 @@ from django_filters.rest_framework import DjangoFilterBackend
|
||||
from rest_framework import filters
|
||||
from rest_framework import generics, permissions
|
||||
|
||||
from django.db.models import Q
|
||||
from django.conf.urls import url, include
|
||||
from django.shortcuts import get_object_or_404
|
||||
|
||||
from .models import Part, PartCategory, BomItem
|
||||
from .models import SupplierPart
|
||||
@ -65,9 +67,34 @@ class PartDetail(DraftRUDView):
|
||||
|
||||
class PartList(generics.ListCreateAPIView):
|
||||
|
||||
queryset = Part.objects.all()
|
||||
serializer_class = PartSerializer
|
||||
|
||||
def get_queryset(self):
|
||||
print("Get queryset")
|
||||
|
||||
# Does the user wish to filter by category?
|
||||
cat_id = self.request.query_params.get('category', None)
|
||||
|
||||
if cat_id:
|
||||
print("Getting category:", cat_id)
|
||||
category = get_object_or_404(PartCategory, pk=cat_id)
|
||||
|
||||
# Filter by the supplied category
|
||||
flt = Q(category=cat_id)
|
||||
|
||||
if self.request.query_params.get('include_child_categories', None):
|
||||
childs = category.getUniqueChildren()
|
||||
for child in childs:
|
||||
# Ignore the top-level category (already filtered)
|
||||
if child == cat_id:
|
||||
continue
|
||||
flt |= Q(category=child)
|
||||
|
||||
return Part.objects.filter(flt)
|
||||
|
||||
# Default - return all parts
|
||||
return Part.objects.all()
|
||||
|
||||
permission_classes = [
|
||||
permissions.IsAuthenticatedOrReadOnly,
|
||||
]
|
||||
@ -79,7 +106,6 @@ class PartList(generics.ListCreateAPIView):
|
||||
]
|
||||
|
||||
filter_fields = [
|
||||
'category',
|
||||
]
|
||||
|
||||
ordering_fields = [
|
||||
|
@ -120,6 +120,7 @@
|
||||
return {
|
||||
{% if category %}
|
||||
category: {{ category.id }},
|
||||
include_child_categories: true,
|
||||
{% endif %}
|
||||
}
|
||||
},
|
||||
@ -148,21 +149,19 @@
|
||||
field: 'description',
|
||||
title: 'Description',
|
||||
},
|
||||
{% if category == None %}
|
||||
{
|
||||
sortable: true,
|
||||
field: 'category',
|
||||
title: 'Category',
|
||||
formatter: function(value, row, index, field) {
|
||||
if (row.category) {
|
||||
return renderLink(row.category.name, row.category.url);
|
||||
return renderLink(row.category.pathstring, row.category.url);
|
||||
}
|
||||
else {
|
||||
return '';
|
||||
}
|
||||
}
|
||||
},
|
||||
{% endif %}
|
||||
{
|
||||
field: 'total_stock',
|
||||
title: 'Stock',
|
||||
|
Loading…
Reference in New Issue
Block a user