mirror of
https://github.com/lemeow125/Borrowing-TrackerBackend.git
synced 2024-11-17 06:19:26 +08:00
28 lines
1.1 KiB
Python
28 lines
1.1 KiB
Python
from rest_framework import serializers
|
|
from accounts.models import CustomUser
|
|
from equipments.models import EquipmentInstance
|
|
from equipments.serializers import EquipmentInstanceSerializer
|
|
from .models import Transaction
|
|
from accounts.models import CustomUser
|
|
from config.settings import DEBUG
|
|
from .models import BreakageReport
|
|
|
|
|
|
class BreakageReportSerializer(serializers.HyperlinkedModelSerializer):
|
|
transaction = serializers.SlugRelatedField(
|
|
many=False, slug_field='id', queryset=Transaction.objects.all(), required=True)
|
|
|
|
equipments = serializers.SlugRelatedField(
|
|
many=True, slug_field='id', queryset=EquipmentInstance.objects.all())
|
|
|
|
class Meta:
|
|
model = BreakageReport
|
|
fields = ['id', 'transaction', 'equipments', 'resolved', 'timestamp']
|
|
read_only_fields = ['id', 'transaction',
|
|
'equipments', 'resolved', 'timestamp']
|
|
|
|
def to_representation(self, instance):
|
|
representation = super().to_representation(instance)
|
|
representation['equipments'] = [
|
|
eq.__str__() for eq in instance.equipments.all()]
|
|
return representation
|