mirror of
https://github.com/inventree/InvenTree.git
synced 2025-04-29 20:16:44 +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
|
language: python
|
||||||
python:
|
python:
|
||||||
- 3.5
|
- 3.5
|
||||||
- 3.6
|
|
||||||
|
|
||||||
addons:
|
addons:
|
||||||
apt-packages:
|
apt-packages:
|
||||||
|
@ -5,7 +5,9 @@ from django_filters.rest_framework import DjangoFilterBackend
|
|||||||
from rest_framework import filters
|
from rest_framework import filters
|
||||||
from rest_framework import generics, permissions
|
from rest_framework import generics, permissions
|
||||||
|
|
||||||
|
from django.db.models import Q
|
||||||
from django.conf.urls import url, include
|
from django.conf.urls import url, include
|
||||||
|
from django.shortcuts import get_object_or_404
|
||||||
|
|
||||||
from .models import Part, PartCategory, BomItem
|
from .models import Part, PartCategory, BomItem
|
||||||
from .models import SupplierPart
|
from .models import SupplierPart
|
||||||
@ -65,9 +67,34 @@ class PartDetail(DraftRUDView):
|
|||||||
|
|
||||||
class PartList(generics.ListCreateAPIView):
|
class PartList(generics.ListCreateAPIView):
|
||||||
|
|
||||||
queryset = Part.objects.all()
|
|
||||||
serializer_class = PartSerializer
|
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 = [
|
permission_classes = [
|
||||||
permissions.IsAuthenticatedOrReadOnly,
|
permissions.IsAuthenticatedOrReadOnly,
|
||||||
]
|
]
|
||||||
@ -79,7 +106,6 @@ class PartList(generics.ListCreateAPIView):
|
|||||||
]
|
]
|
||||||
|
|
||||||
filter_fields = [
|
filter_fields = [
|
||||||
'category',
|
|
||||||
]
|
]
|
||||||
|
|
||||||
ordering_fields = [
|
ordering_fields = [
|
||||||
|
@ -120,6 +120,7 @@
|
|||||||
return {
|
return {
|
||||||
{% if category %}
|
{% if category %}
|
||||||
category: {{ category.id }},
|
category: {{ category.id }},
|
||||||
|
include_child_categories: true,
|
||||||
{% endif %}
|
{% endif %}
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
@ -148,21 +149,19 @@
|
|||||||
field: 'description',
|
field: 'description',
|
||||||
title: 'Description',
|
title: 'Description',
|
||||||
},
|
},
|
||||||
{% if category == None %}
|
|
||||||
{
|
{
|
||||||
sortable: true,
|
sortable: true,
|
||||||
field: 'category',
|
field: 'category',
|
||||||
title: 'Category',
|
title: 'Category',
|
||||||
formatter: function(value, row, index, field) {
|
formatter: function(value, row, index, field) {
|
||||||
if (row.category) {
|
if (row.category) {
|
||||||
return renderLink(row.category.name, row.category.url);
|
return renderLink(row.category.pathstring, row.category.url);
|
||||||
}
|
}
|
||||||
else {
|
else {
|
||||||
return '';
|
return '';
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
{% endif %}
|
|
||||||
{
|
{
|
||||||
field: 'total_stock',
|
field: 'total_stock',
|
||||||
title: 'Stock',
|
title: 'Stock',
|
||||||
|
Loading…
x
Reference in New Issue
Block a user