2
0
mirror of https://github.com/inventree/InvenTree.git synced 2025-06-19 21:45:39 +00:00

Simplify extended filters

This commit is contained in:
Oliver Walters
2019-05-16 19:14:43 +10:00
parent e1558a7a96
commit b4df96aaee
5 changed files with 4 additions and 37 deletions

View File

@ -12,7 +12,6 @@ from rest_framework.response import Response
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.urls import reverse
@ -109,20 +108,7 @@ class PartList(generics.ListCreateAPIView):
if cat_id:
try:
category = PartCategory.objects.get(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 str(child) == str(cat_id):
continue
flt |= Q(category=child)
parts_list = parts_list.filter(flt)
parts_list = parts_list.filter(category__in=category.getUniqueChildren())
except PartCategory.DoesNotExist:
pass

View File

@ -153,7 +153,6 @@
query: {
{% if category %}
category: {{ category.id }},
include_child_categories: true,
{% endif %}
},
buttons: ['#part-options'],

View File

@ -105,13 +105,6 @@ class PartAPITest(APITestCase):
url = reverse('api-part-list')
data = {'category': 1}
response = self.client.get(url, data, format='json')
# There should be 1 part in this category
self.assertEqual(len(response.data), 0)
data['include_child_categories'] = 1
# Now request to include child categories
response = self.client.get(url, data, format='json')