From e4c0cecb34b159392f95b081916b13534754603d Mon Sep 17 00:00:00 2001 From: jdlugosz963 Date: Wed, 15 Dec 2021 14:55:22 +0100 Subject: upgrade Group messages api --- chat_api/models.py | 2 +- chat_api/serializers.py | 4 ++++ 2 files changed, 5 insertions(+), 1 deletion(-) (limited to 'chat_api') diff --git a/chat_api/models.py b/chat_api/models.py index 3be795a..3a3f51e 100644 --- a/chat_api/models.py +++ b/chat_api/models.py @@ -18,7 +18,7 @@ class Group(models.Model): create_date = models.DateTimeField(auto_now=True) def __str__(self): - return self.name + return str(self.pk) + " " + self.name class Gm(models.Model): sender = models.ForeignKey(User, related_name="sender_gm", on_delete=models.CASCADE) diff --git a/chat_api/serializers.py b/chat_api/serializers.py index 15828be..dee0c45 100644 --- a/chat_api/serializers.py +++ b/chat_api/serializers.py @@ -1,6 +1,9 @@ from django.db.models import fields +from django.contrib.auth.models import User + from rest_framework import serializers from .models import * +from auth_api.serializers import UserSerializer class GroupSerializer(serializers.ModelSerializer): is_mine = serializers.SerializerMethodField('_is_mine') @@ -30,6 +33,7 @@ class DmSerializer(serializers.ModelSerializer): class GmSerializer(serializers.ModelSerializer): is_mine = serializers.SerializerMethodField('_is_mine') + sender = UserSerializer(read_only=True) def _is_mine(self, obj): request = self.context.get('request') -- cgit v1.2.3