InvenTree/InvenTree/build/serializers.py
Oliver Walters 1d36ea3e2e Add a 'full_name' field for Part
- Combines IPN | Name | Variant
- Use this to display in most views
2019-05-12 12:16:04 +10:00

61 lines
1.5 KiB
Python

"""
JSON serializers for Build API
"""
# -*- coding: utf-8 -*-
from __future__ import unicode_literals
from rest_framework import serializers
from InvenTree.serializers import InvenTreeModelSerializer
from stock.serializers import StockItemSerializerBrief
from .models import Build, BuildItem
class BuildSerializer(InvenTreeModelSerializer):
""" Serializes a Build object """
url = serializers.CharField(source='get_absolute_url', read_only=True)
status_text = serializers.CharField(source='get_status_display', read_only=True)
class Meta:
model = Build
fields = [
'pk',
'url',
'title',
'creation_date',
'completion_date',
'part',
'quantity',
'status',
'status_text',
'notes']
read_only_fields = [
'status',
'creation_date',
'completion_data',
'status_text',
]
class BuildItemSerializer(InvenTreeModelSerializer):
""" Serializes a BuildItem object """
part = serializers.IntegerField(source='stock_item.part.pk', read_only=True)
part_name = serializers.CharField(source='stock_item.part.full_name', read_only=True)
stock_item_detail = StockItemSerializerBrief(source='stock_item', read_only=True)
class Meta:
model = BuildItem
fields = [
'pk',
'build',
'part',
'part_name',
'stock_item',
'stock_item_detail',
'quantity'
]