diff --git a/InvenTree/part/api.py b/InvenTree/part/api.py index 424f03fd0b..b55e027152 100644 --- a/InvenTree/part/api.py +++ b/InvenTree/part/api.py @@ -98,20 +98,17 @@ class PartThumbs(generics.ListAPIView): # Get all Parts which have an associated image queryset = Part.objects.all().exclude(image='') + # Return the most popular parts first data = queryset.values( 'image', ).annotate(count=Count('image')).order_by('-count') - print("Parts with img:", queryset.count()) - - print(data) - return Response(data) class PartDetail(generics.RetrieveUpdateAPIView): """ API endpoint for detail view of a single Part object """ - + queryset = Part.objects.all() serializer_class = part_serializers.PartSerializer diff --git a/InvenTree/part/models.py b/InvenTree/part/models.py index 7d33a782de..4109946dce 100644 --- a/InvenTree/part/models.py +++ b/InvenTree/part/models.py @@ -12,7 +12,6 @@ from django.core.exceptions import ValidationError from django.urls import reverse from django.conf import settings -from django.core.files.base import ContentFile from django.db import models, transaction from django.db.models import Sum from django.db.models import prefetch_related_objects diff --git a/InvenTree/part/templates/part/part_base.html b/InvenTree/part/templates/part/part_base.html index 13d82c573b..cecf4244ea 100644 --- a/InvenTree/part/templates/part/part_base.html +++ b/InvenTree/part/templates/part/part_base.html @@ -218,14 +218,22 @@ ); }); + function onSelectImage(response) { + // Callback when the image-selection modal form is displayed + // Populate the form with image data (requested via AJAX) $("#modal-form").find("#image-select-table").bootstrapTable({ pagination: true, pageSize: 25, url: "{% url 'api-part-thumbs' %}", showHeader: false, + clickToSelect: true, + singleSelect: true, columns: [ + { + checkbox: true, + }, { field: 'image', title: 'Image', @@ -234,6 +242,13 @@ } } ], + onCheck: function(row, element) { + + // Update the selected image in the form + var ipt = $("#modal-form").find("#image-input"); + ipt.val(row.image); + + } }); } diff --git a/InvenTree/part/templates/part/select_image.html b/InvenTree/part/templates/part/select_image.html index 851688bf05..5e7667824d 100644 --- a/InvenTree/part/templates/part/select_image.html +++ b/InvenTree/part/templates/part/select_image.html @@ -4,14 +4,15 @@ {{ block.super }} -Select from existing images. {% endblock %} {% block form %}