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

Merge pull request #363 from SchrodingersGat/rest-simplify

Rest simplify
This commit is contained in:
Oliver
2019-05-23 23:03:39 +10:00
committed by GitHub
16 changed files with 122 additions and 22 deletions

View File

@ -22,6 +22,7 @@ from .serializers import CategorySerializer
from .serializers import PartStarSerializer
from InvenTree.views import TreeSerializer
from InvenTree.helpers import str2bool
class PartCategoryTree(TreeSerializer):
@ -203,8 +204,20 @@ class BomList(generics.ListCreateAPIView):
- GET: Return list of BomItem objects
- POST: Create a new BomItem object
"""
serializer_class = BomItemSerializer
def get_serializer(self, *args, **kwargs):
# Do we wish to include extra detail?
part_detail = str2bool(self.request.GET.get('part_detail', None))
sub_part_detail = str2bool(self.request.GET.get('sub_part_detail', None))
kwargs['part_detail'] = part_detail
kwargs['sub_part_detail'] = sub_part_detail
kwargs['context'] = self.get_serializer_context()
return self.serializer_class(*args, **kwargs)
def get_queryset(self):
queryset = BomItem.objects.all()

View File

@ -125,6 +125,21 @@ class BomItemSerializer(InvenTreeModelSerializer):
sub_part_detail = PartBriefSerializer(source='sub_part', many=False, read_only=True)
price_range = serializers.CharField(read_only=True)
def __init__(self, *args, **kwargs):
# part_detail and sub_part_detail serializers are only included if requested.
# This saves a bunch of database requests
part_detail = kwargs.pop('part_detail', False)
sub_part_detail = kwargs.pop('sub_part_detail', False)
super(BomItemSerializer, self).__init__(*args, **kwargs)
if part_detail is not True:
self.fields.pop('part_detail')
if sub_part_detail is not True:
self.fields.pop('sub_part_detail')
@staticmethod
def setup_eager_loading(queryset):
queryset = queryset.prefetch_related('part')

View File

@ -72,7 +72,8 @@
editable: {{ editing_enabled }},
bom_url: "{% url 'api-bom-list' %}",
part_url: "{% url 'api-part-list' %}",
parent_id: {{ part.id }}
parent_id: {{ part.id }} ,
sub_part_detail: true,
});
{% if editing_enabled %}

View File

@ -35,6 +35,7 @@
sortable: true,
search: true,
pagination: true,
pageSize: 50,
queryParams: function(p) {
return {
part: {{ part.id }},

View File

@ -37,6 +37,8 @@
loadStockTable($("#stock-table"), {
params: {
part: {{ part.id }},
location_detail: true,
part_detail: true,
},
buttons: [
'#stock-options',

View File

@ -30,7 +30,8 @@
formatNoMatches: function() { return "{{ part.full_name }} is not used to make any other parts"; },
queryParams: function(p) {
return {
sub_part: {{ part.id }}
sub_part: {{ part.id }},
part_detail: true,
}
},
columns: [