Skip to content

Commit

Permalink
Fix the endpoint to view project chats in order (#334)
Browse files Browse the repository at this point in the history
* endpoint to view project chats in order

* send username along with chats to admin

* refactor

* show username in chats list to admin
  • Loading branch information
Pranshu1902 authored Oct 3, 2023
1 parent 774e59c commit 054e4dd
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 2 deletions.
7 changes: 6 additions & 1 deletion ayushma/serializers/chat.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -15,12 +16,14 @@ class Meta:
"title",
"created_at",
"modified_at",
"username",
"project",
)
read_only_fields = (
"external_id",
"created_at",
"modified_at",
"username",
"project",
)

Expand Down Expand Up @@ -109,20 +112,22 @@ 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",
"prompt",
"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")
Expand Down
4 changes: 3 additions & 1 deletion ayushma/views/chat.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down

0 comments on commit 054e4dd

Please sign in to comment.