shimatta-kenkyusho/shimatta_kenkyusho/api/serializers.py

56 lines
2.0 KiB
Python
Raw Normal View History

2021-08-07 19:47:34 +02:00
from django.contrib.auth.models import User, Group
from rest_framework import serializers
from parts import models as parts_models
class UserSerializer(serializers.HyperlinkedModelSerializer):
class Meta:
model = User
fields = ['username', 'email', 'first_name', 'last_name', 'groups']
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):
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', 'parent_storage', 'responsible', 'full_path']
class ComponentSerializer(serializers.HyperlinkedModelSerializer):
package_data = PackageSerializerNoLink(source='package', read_only=True)
class Meta:
model = parts_models.Component
fields = ['url', 'id', 'name', 'package_data', 'package', 'pref_distri']
class StockSerializer(serializers.HyperlinkedModelSerializer):
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):
class Meta:
model = parts_models.Distributor
fields = '__all__'
class StockIncrementDecrementSerializer(serializers.Serializer):
increment = serializers.IntegerField()