shimatta-kenkyusho/shimatta_kenkyusho/api/serializers.py

80 lines
3.0 KiB
Python
Raw Normal View History

from django.contrib.auth.models import Group
from django.contrib.auth import get_user_model
2021-08-07 19:47:34 +02:00
from rest_framework import serializers
from parts import models as parts_models
class UserSerializer(serializers.HyperlinkedModelSerializer):
class Meta:
model = get_user_model()
fields = ['id', 'username', 'email', 'first_name', 'last_name', 'groups']
2021-08-07 19:47:34 +02:00
class GroupSerializer(serializers.HyperlinkedModelSerializer):
class Meta:
model = Group
fields = ['url', 'id', 'url', 'name']
class PackageSerializerNoLink(serializers.ModelSerializer):
class Meta:
model = parts_models.Package
fields = '__all__'
class PackageSerializer(serializers.HyperlinkedModelSerializer):
id = serializers.ReadOnlyField()
2021-08-07 19:47:34 +02:00
class Meta:
model = parts_models.Package
fields = '__all__'
class StorageSerializer(serializers.HyperlinkedModelSerializer):
full_path = serializers.ReadOnlyField(source='get_full_path')
class Meta:
model = parts_models.Storage
fields = ['url', 'id', 'name', 'verbose_name', 'parent_storage', 'responsible', 'template', 'full_path']
2021-08-07 19:47:34 +02:00
class ComponentSerializer(serializers.HyperlinkedModelSerializer):
package_data = PackageSerializerNoLink(source='package', read_only=True)
ro_manufacturer_name = serializers.ReadOnlyField(source='manufacturer.name')
ro_image = serializers.ReadOnlyField(source='get_resolved_image')
2021-08-07 19:47:34 +02:00
class Meta:
model = parts_models.Component
fields = ['url', 'id', 'name', 'package_data', 'package', 'pref_distri', 'image', 'manufacturer', 'ro_manufacturer_name', 'ro_image']
2021-08-07 19:47:34 +02:00
class StockSerializer(serializers.HyperlinkedModelSerializer):
id = serializers.ReadOnlyField()
2021-08-07 19:47:34 +02:00
ro_package_name = serializers.ReadOnlyField(source='component.package.name')
ro_component_name = serializers.ReadOnlyField(source='component.name')
ro_manufacturer_name = serializers.ReadOnlyField(source='component.manufacturer.name')
ro_image = serializers.ReadOnlyField(source='component.get_resolved_image')
class Meta:
model = parts_models.Stock
fields = '__all__'
class DistributorSerializer(serializers.HyperlinkedModelSerializer):
id = serializers.ReadOnlyField()
2021-08-07 19:47:34 +02:00
class Meta:
model = parts_models.Distributor
fields = '__all__'
class StockIncrementDecrementSerializer(serializers.Serializer):
increment = serializers.IntegerField()
class ManufacturerSerializer(serializers.HyperlinkedModelSerializer):
id = serializers.ReadOnlyField()
class Meta:
model = parts_models.Manufacturer
fields = '__all__'
class ComponentTypeSerializer(serializers.HyperlinkedModelSerializer):
id = serializers.ReadOnlyField()
class Meta:
model = parts_models.ComponentType
fields = '__all__'
class ComponentParameterTypeSerializer(serializers.HyperlinkedModelSerializer):
id = serializers.ReadOnlyField()
2022-01-03 17:38:50 +01:00
descriptive_name = serializers.ReadOnlyField()
class Meta:
model = parts_models.ComponentParameterType
fields = '__all__'