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 ++++ index.http | 6 ++++++ lom_api/settings.py | 3 ++- 4 files changed, 13 insertions(+), 2 deletions(-) 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') diff --git a/index.http b/index.http index 6349a84..ef0ba9f 100644 --- a/index.http +++ b/index.http @@ -32,3 +32,9 @@ content-type: application/json GET http://localhost:8000/api/auth/info/? Authorization: Token bd057a90565d85b2efa23f73deb9e5afdb4e4d56b24ba405a1cf33b66b49f4ed + +### + +GET http://localhost:8000/api/chat/groups/detail/22/messages/ +Authorization: Token b4bd0a69d9f78c9447b4f7581a8b8cc53f5732a7f6542db9a5fea093ce734b2c +content-type: application/json diff --git a/lom_api/settings.py b/lom_api/settings.py index a09c7a7..77a754e 100644 --- a/lom_api/settings.py +++ b/lom_api/settings.py @@ -50,8 +50,9 @@ REST_FRAMEWORK = { } REST_KNOX = { -# 'TOKEN_LIMIT_PER_USER': 1, + 'TOKEN_TTL': None, } + MIDDLEWARE = [ 'django.middleware.security.SecurityMiddleware', -- cgit v1.2.3