mirror of
https://github.com/inventree/InvenTree
synced 2024-08-30 18:33:04 +00:00
0cfb243eb3
- https://docs.djangoproject.com/en/2.2/ref/models/options/#django.db.models.Options.db_table - https://stackoverflow.com/questions/3519143/django-how-to-specify-a-database-for-a-model - And others, presumably
93 lines
2.2 KiB
Python
93 lines
2.2 KiB
Python
"""
|
|
JSON serializers for Company app
|
|
"""
|
|
|
|
from rest_framework import serializers
|
|
|
|
from .models import Company
|
|
from .models import SupplierPart, SupplierPriceBreak
|
|
|
|
from part.serializers import PartBriefSerializer
|
|
|
|
|
|
class CompanyBriefSerializer(serializers.ModelSerializer):
|
|
""" Serializer for Company object (limited detail) """
|
|
|
|
url = serializers.CharField(source='get_absolute_url', read_only=True)
|
|
|
|
class Meta:
|
|
model = Company
|
|
fields = [
|
|
'pk',
|
|
'url',
|
|
'name'
|
|
]
|
|
|
|
|
|
class CompanySerializer(serializers.ModelSerializer):
|
|
""" Serializer for Company object (full detail) """
|
|
|
|
url = serializers.CharField(source='get_absolute_url', read_only=True)
|
|
part_count = serializers.CharField(read_only=True)
|
|
|
|
class Meta:
|
|
model = Company
|
|
fields = [
|
|
'id',
|
|
'url',
|
|
'name',
|
|
'description',
|
|
'website',
|
|
'name',
|
|
'phone',
|
|
'address',
|
|
'email',
|
|
'contact',
|
|
'URL',
|
|
'image',
|
|
'notes',
|
|
'is_customer',
|
|
'is_supplier',
|
|
'part_count'
|
|
]
|
|
|
|
|
|
class SupplierPartSerializer(serializers.ModelSerializer):
|
|
""" Serializer for SupplierPart object """
|
|
|
|
url = serializers.CharField(source='get_absolute_url', read_only=True)
|
|
|
|
part_detail = PartBriefSerializer(source='part', many=False, read_only=True)
|
|
|
|
supplier_name = serializers.CharField(source='supplier.name', read_only=True)
|
|
supplier_logo = serializers.CharField(source='supplier.get_image_url', read_only=True)
|
|
|
|
class Meta:
|
|
model = SupplierPart
|
|
fields = [
|
|
'pk',
|
|
'url',
|
|
'part',
|
|
'part_detail',
|
|
'supplier',
|
|
'supplier_name',
|
|
'supplier_logo',
|
|
'SKU',
|
|
'manufacturer',
|
|
'MPN',
|
|
'URL',
|
|
]
|
|
|
|
|
|
class SupplierPriceBreakSerializer(serializers.ModelSerializer):
|
|
""" Serializer for SupplierPriceBreak object """
|
|
|
|
class Meta:
|
|
model = SupplierPriceBreak
|
|
fields = [
|
|
'pk',
|
|
'part',
|
|
'quantity',
|
|
'cost'
|
|
]
|