Logic fix for part filtering

This commit is contained in:
Oliver Walters 2020-04-11 22:57:16 +10:00
parent e86bc4fa6d
commit e1c6ad7761

View File

@ -149,6 +149,13 @@ class PartList(generics.ListCreateAPIView):
- GET: Return list of objects - GET: Return list of objects
- POST: Create a new Part object - POST: Create a new Part object
The Part object list can be filtered by:
- category: Filter by PartCategory reference
- cascade: If true, include parts from sub-categories
- is_template: Is the part a template part?
- variant_of: Filter by variant_of Part reference
- assembly: Filter by assembly field
""" """
serializer_class = part_serializers.PartSerializer serializer_class = part_serializers.PartSerializer
@ -291,13 +298,13 @@ class PartList(generics.ListCreateAPIView):
cascade = str2bool(self.request.query_params.get('cascade', False)) cascade = str2bool(self.request.query_params.get('cascade', False))
if cat_id is not None: if cat_id is None:
# Top-level parts
if isNull(cat_id): if not cascade:
parts_list = parts_list.filter(category=None) parts_list = parts_list.filter(category=None)
else: else:
try: try:
cat_id = int(cat_id)
category = PartCategory.objects.get(pk=cat_id) category = PartCategory.objects.get(pk=cat_id)
# If '?cascade=true' then include parts which exist in sub-categories # If '?cascade=true' then include parts which exist in sub-categories