Merge pull request #695 from SchrodingersGat/api-fixes

Api fixes
This commit is contained in:
Oliver 2020-04-05 19:22:09 +10:00 committed by GitHub
commit 64a1f0f0a1
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 34 additions and 21 deletions

View File

@ -243,6 +243,12 @@ class PartList(generics.ListCreateAPIView):
else: else:
item['category__name'] = None item['category__name'] = None
# Rename "URL" to "link" to distinguish from lower-case "url",
# which is the web address of the item itself
if 'URL' in item.keys():
item['link'] = item['URL']
del item['URL']
return Response(data) return Response(data)
def get_queryset(self): def get_queryset(self):

View File

@ -78,12 +78,16 @@ class PartSerializer(InvenTreeModelSerializer):
Used when displaying all details of a single component. Used when displaying all details of a single component.
""" """
url = serializers.CharField(source='get_absolute_url', read_only=True) allocated_stock = serializers.FloatField(source='allocation_count', read_only=True)
image = serializers.CharField(source='get_image_url', read_only=True) bom_items = serializers.IntegerField(source='bom_count', read_only=True)
thumbnail = serializers.CharField(source='get_thumbnail_url', read_only=True) building = serializers.FloatField(source='quantity_being_built', read_only=False)
category_name = serializers.CharField(source='category_path', read_only=True) category_name = serializers.CharField(source='category_path', read_only=True)
image = serializers.CharField(source='get_image_url', read_only=True)
allocated_stock = serializers.IntegerField(source='allocation_count', read_only=True) on_order = serializers.FloatField(read_only=True)
thumbnail = serializers.CharField(source='get_thumbnail_url', read_only=True)
url = serializers.CharField(source='get_absolute_url', read_only=True)
link = serializers.CharField(source='URL')
used_in = serializers.IntegerField(source='used_in_count', read_only=True)
@staticmethod @staticmethod
def setup_eager_loading(queryset): def setup_eager_loading(queryset):
@ -97,31 +101,34 @@ class PartSerializer(InvenTreeModelSerializer):
model = Part model = Part
partial = True partial = True
fields = [ fields = [
'pk', 'active',
'url', # Link to the part detail page 'allocated_stock',
'assembly',
'bom_items',
'building',
'category', 'category',
'category_name', 'category_name',
'image', 'component',
'thumbnail', 'description',
'full_name', 'full_name',
'name', 'image',
'IPN', 'IPN',
'is_template', 'is_template',
'variant_of',
'description',
'keywords', 'keywords',
'URL', 'link',
'total_stock', 'name',
'allocated_stock', 'notes',
'on_order', 'on_order',
'units', 'pk',
'trackable',
'assembly',
'component',
'trackable',
'purchaseable', 'purchaseable',
'salable', 'salable',
'active', 'thumbnail',
'trackable',
'total_stock',
'units',
'used_in',
'url', # Link to the part detail page
'variant_of',
'virtual', 'virtual',
] ]