mirror of
https://github.com/inventree/InvenTree
synced 2024-08-30 18:33:04 +00:00
Override get_queryset for BuildItem API view
- Special management to allow filtering by part
This commit is contained in:
parent
c29827e45a
commit
192f604b76
@ -36,7 +36,7 @@ class BuildList(generics.ListCreateAPIView):
|
||||
]
|
||||
|
||||
filter_fields = [
|
||||
'build',
|
||||
'part',
|
||||
]
|
||||
|
||||
|
||||
@ -47,16 +47,33 @@ class BuildItemList(generics.ListCreateAPIView):
|
||||
- POST: Create a new BuildItem object
|
||||
"""
|
||||
|
||||
queryset = BuildItem.objects.all()
|
||||
serializer_class = BuildItemSerializer
|
||||
|
||||
def get_queryset(self):
|
||||
""" Override the queryset method,
|
||||
to allow filtering by stock_item.part
|
||||
"""
|
||||
|
||||
# Does the user wish to filter by part?
|
||||
part_pk = self.request.query_params.get('part', None)
|
||||
|
||||
query = BuildItem.objects.all()
|
||||
|
||||
if part_pk:
|
||||
query = query.filter(stock_item__part=part_pk)
|
||||
|
||||
return query
|
||||
|
||||
permission_classes = [
|
||||
permissions.IsAuthenticatedOrReadOnly,
|
||||
]
|
||||
|
||||
filter_backends = [
|
||||
DjangoFilterBackend,
|
||||
]
|
||||
|
||||
filter_fields = [
|
||||
'build',
|
||||
'part',
|
||||
'stock_item'
|
||||
]
|
||||
|
||||
|
@ -34,13 +34,16 @@ class BuildSerializer(InvenTreeModelSerializer):
|
||||
class BuildItemSerializer(InvenTreeModelSerializer):
|
||||
""" Serializes a BuildItem object """
|
||||
|
||||
part = serializers.CharField(source='stock_item.part', read_only=True)
|
||||
part = serializers.IntegerField(source='stock_item.part.pk', read_only=True)
|
||||
part_name = serializers.CharField(source='stock_item.part', read_only=True)
|
||||
|
||||
class Meta:
|
||||
model = BuildItem
|
||||
fields = [
|
||||
'pk',
|
||||
'build',
|
||||
'part',
|
||||
'part_name',
|
||||
'stock_item',
|
||||
'quantity'
|
||||
]
|
||||
|
Loading…
Reference in New Issue
Block a user