diff options
author | jdlugosz963 <jdlugosz963@gmail.com> | 2021-12-15 22:42:32 +0100 |
---|---|---|
committer | jdlugosz963 <jdlugosz963@gmail.com> | 2021-12-15 22:42:32 +0100 |
commit | 1467d965dc8f428dc1946a1f4f7c0e749b20e570 (patch) | |
tree | bbce6eb6440df586e0b0a3466f5128911181a04c /chat_api | |
parent | e4c0cecb34b159392f95b081916b13534754603d (diff) | |
download | lom_api-1467d965dc8f428dc1946a1f4f7c0e749b20e570.tar.gz lom_api-1467d965dc8f428dc1946a1f4f7c0e749b20e570.zip |
repair group api bug
Diffstat (limited to 'chat_api')
-rw-r--r-- | chat_api/models.py | 4 | ||||
-rw-r--r-- | chat_api/serializers.py | 5 | ||||
-rw-r--r-- | chat_api/views.py | 5 |
3 files changed, 10 insertions, 4 deletions
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 | |||
4 | 4 | ||
5 | class Dm(models.Model): | 5 | class Dm(models.Model): |
6 | sender = models.ForeignKey(User, related_name="sender_dm", on_delete=models.CASCADE) | 6 | sender = models.ForeignKey(User, related_name="sender_dm", on_delete=models.CASCADE) |
7 | reciever = models.ForeignKey(User, related_name="receiver_dm", on_delete=models.CASCADE) | 7 | receiver = models.ForeignKey(User, related_name="receiver_dm", on_delete=models.CASCADE) |
8 | message = models.TextField(null=False) | 8 | message = models.TextField(null=False) |
9 | create_date = models.DateTimeField(auto_now=True) | 9 | create_date = models.DateTimeField(auto_now=True) |
10 | 10 | ||
@@ -22,7 +22,7 @@ class Group(models.Model): | |||
22 | 22 | ||
23 | class Gm(models.Model): | 23 | class Gm(models.Model): |
24 | sender = models.ForeignKey(User, related_name="sender_gm", on_delete=models.CASCADE) | 24 | sender = models.ForeignKey(User, related_name="sender_gm", on_delete=models.CASCADE) |
25 | reciever = models.ForeignKey(Group, related_name="receiver_gm", on_delete=models.CASCADE) | 25 | receiver = models.ForeignKey(Group, related_name="receiver_gm", on_delete=models.CASCADE) |
26 | message = models.TextField(null=False) | 26 | message = models.TextField(null=False) |
27 | create_date = models.DateTimeField(auto_now=True) | 27 | create_date = models.DateTimeField(auto_now=True) |
28 | 28 | ||
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): | |||
31 | model = Dm | 31 | model = Dm |
32 | fields = '__all__' | 32 | fields = '__all__' |
33 | 33 | ||
34 | class GmSimpleSerializer(serializers.ModelSerializer): | ||
35 | class Meta: | ||
36 | model = Gm | ||
37 | fields = '__all__' | ||
38 | |||
34 | class GmSerializer(serializers.ModelSerializer): | 39 | class GmSerializer(serializers.ModelSerializer): |
35 | is_mine = serializers.SerializerMethodField('_is_mine') | 40 | is_mine = serializers.SerializerMethodField('_is_mine') |
36 | sender = UserSerializer(read_only=True) | 41 | 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 | |||
12 | 12 | ||
13 | from .models import * | 13 | from .models import * |
14 | from .serializers import * | 14 | from .serializers import * |
15 | from auth_api.serializers import UserSerializer | ||
15 | 16 | ||
16 | 17 | ||
17 | def set_users(request): | 18 | def set_users(request): |
@@ -108,8 +109,8 @@ class GmsView(APIView): | |||
108 | raise Http404 | 109 | raise Http404 |
109 | 110 | ||
110 | request.data['sender'] = request.user.pk | 111 | request.data['sender'] = request.user.pk |
111 | request.data['reciever'] = pk | 112 | request.data['receiver'] = pk |
112 | serializer = GmSerializer(data=request.data) | 113 | serializer = GmSimpleSerializer(data=request.data) |
113 | serializer.is_valid(raise_exception=True) | 114 | serializer.is_valid(raise_exception=True) |
114 | serializer.save() | 115 | serializer.save() |
115 | 116 | ||