From 1467d965dc8f428dc1946a1f4f7c0e749b20e570 Mon Sep 17 00:00:00 2001 From: jdlugosz963 Date: Wed, 15 Dec 2021 22:42:32 +0100 Subject: repair group api bug --- chat_api/models.py | 4 ++-- chat_api/serializers.py | 5 +++++ chat_api/views.py | 5 +++-- 3 files changed, 10 insertions(+), 4 deletions(-) (limited to 'chat_api') diff --git a/chat_api/models.py b/chat_api/models.py index 3a3f51e..c3b44b6 100644 --- a/chat_api/models.py +++ b/chat_api/models.py @@ -4,7 +4,7 @@ from django.db.models.base import Model class Dm(models.Model): sender = models.ForeignKey(User, related_name="sender_dm", on_delete=models.CASCADE) - reciever = models.ForeignKey(User, related_name="receiver_dm", on_delete=models.CASCADE) + receiver = models.ForeignKey(User, related_name="receiver_dm", on_delete=models.CASCADE) message = models.TextField(null=False) create_date = models.DateTimeField(auto_now=True) @@ -22,7 +22,7 @@ class Group(models.Model): class Gm(models.Model): sender = models.ForeignKey(User, related_name="sender_gm", on_delete=models.CASCADE) - reciever = models.ForeignKey(Group, related_name="receiver_gm", on_delete=models.CASCADE) + receiver = models.ForeignKey(Group, related_name="receiver_gm", on_delete=models.CASCADE) message = models.TextField(null=False) create_date = models.DateTimeField(auto_now=True) diff --git a/chat_api/serializers.py b/chat_api/serializers.py index dee0c45..d182876 100644 --- a/chat_api/serializers.py +++ b/chat_api/serializers.py @@ -31,6 +31,11 @@ class DmSerializer(serializers.ModelSerializer): model = Dm fields = '__all__' +class GmSimpleSerializer(serializers.ModelSerializer): + class Meta: + model = Gm + fields = '__all__' + class GmSerializer(serializers.ModelSerializer): is_mine = serializers.SerializerMethodField('_is_mine') sender = UserSerializer(read_only=True) diff --git a/chat_api/views.py b/chat_api/views.py index 3ea0e54..6783eba 100644 --- a/chat_api/views.py +++ b/chat_api/views.py @@ -12,6 +12,7 @@ from django.db.models.query import Q from .models import * from .serializers import * +from auth_api.serializers import UserSerializer def set_users(request): @@ -108,8 +109,8 @@ class GmsView(APIView): raise Http404 request.data['sender'] = request.user.pk - request.data['reciever'] = pk - serializer = GmSerializer(data=request.data) + request.data['receiver'] = pk + serializer = GmSimpleSerializer(data=request.data) serializer.is_valid(raise_exception=True) serializer.save() -- cgit v1.2.3