From d50ca983da1692b8e994b0936207b8f6bb1117af Mon Sep 17 00:00:00 2001 From: Keannu Bernasol Date: Mon, 20 Nov 2023 01:53:19 +0800 Subject: [PATCH] Fixed last_updated_by field for equipment and equipment instances --- equipment_tracker/equipments/serializers.py | 9 +++++---- 1 file changed, 5 insertions(+), 4 deletions(-) diff --git a/equipment_tracker/equipments/serializers.py b/equipment_tracker/equipments/serializers.py index d331100..4ab60fc 100644 --- a/equipment_tracker/equipments/serializers.py +++ b/equipment_tracker/equipments/serializers.py @@ -30,12 +30,13 @@ class EquipmentSerializer(serializers.HyperlinkedModelSerializer): read_only_fields = ('id', 'last_updated', 'last_updated_by', 'date_added') + @extend_schema_field(OpenApiTypes.STR) def get_history_user(self, obj): return obj.history_user.username if obj.history_user else None @extend_schema_field(OpenApiTypes.STR) def get_last_updated_by(self, obj): - return obj.history.first().history_user if obj.history.first().history_user else None + return obj.history.first().history_user.username if obj.history.first().history_user else None class EquipmentLogsSerializer(serializers.HyperlinkedModelSerializer): @@ -74,7 +75,7 @@ class EquipmentLogSerializer(serializers.HyperlinkedModelSerializer): @extend_schema_field(OpenApiTypes.STR) def get_last_updated_by(self, obj): - return obj.history.first().history_user if obj.history.first().history_user else None + return obj.history.first().history_user.username if obj.history.first().history_user else None # -- Equipment Instance Serializers @@ -117,7 +118,7 @@ class EquipmentInstanceSerializer(serializers.HyperlinkedModelSerializer): @extend_schema_field(OpenApiTypes.STR) def get_last_updated_by(self, obj): - return obj.history.first().history_user if obj.history.first().history_user else None + return obj.history.first().history_user.username if obj.history.first().history_user else None class EquipmentInstanceLogsSerializer(serializers.HyperlinkedModelSerializer): @@ -166,4 +167,4 @@ class EquipmentInstanceLogSerializer(serializers.HyperlinkedModelSerializer): @extend_schema_field(OpenApiTypes.STR) def get_last_updated_by(self, obj): - return obj.history.first().history_user if obj.history.first().history_user else None + return obj.history.first().history_user.username if obj.history.first().history_user else None