diff --git a/ayushma/serializers/chat.py b/ayushma/serializers/chat.py index 6bb1ab14..061e04df 100644 --- a/ayushma/serializers/chat.py +++ b/ayushma/serializers/chat.py @@ -7,6 +7,7 @@ class ChatSerializer(serializers.ModelSerializer): project = ProjectSerializer(read_only=True) + username = serializers.CharField(source='user.username', read_only=True) class Meta: model = Chat @@ -15,12 +16,14 @@ class Meta: "title", "created_at", "modified_at", + "username", "project", ) read_only_fields = ( "external_id", "created_at", "modified_at", + "username", "project", ) @@ -109,12 +112,14 @@ class ConverseSerializer(serializers.Serializer): class ChatDetailSerializer(serializers.ModelSerializer): chats = serializers.SerializerMethodField() message = ConverseSerializer(required=False) + username = serializers.CharField(source='user.username', read_only=True) class Meta: model = Chat fields = ( "external_id", "title", + "username", "created_at", "modified_at", "chats", @@ -122,7 +127,7 @@ class Meta: "message", "model", ) - read_only_fields = ("external_id", "created_at", "modified_at", "chats") + read_only_fields = ("external_id", "created_at", "modified_at", "chats", "username") def get_chats(self, obj): chatmessages = ChatMessage.objects.filter(chat=obj).order_by("created_at") diff --git a/ayushma/views/chat.py b/ayushma/views/chat.py index 0006ed68..7b1c3f67 100644 --- a/ayushma/views/chat.py +++ b/ayushma/views/chat.py @@ -58,7 +58,9 @@ def get_parsers(self): def get_queryset(self): user = self.request.user project_id = self.kwargs["project_external_id"] - queryset = self.queryset.filter(project__external_id=project_id) + queryset = self.queryset.filter(project__external_id=project_id).order_by( + "-created_at" + ) if user.is_superuser and self.action == "list_all": return queryset