summaryrefslogtreecommitdiffstats
path: root/chat_api
diff options
context:
space:
mode:
Diffstat (limited to 'chat_api')
-rw-r--r--chat_api/models.py4
-rw-r--r--chat_api/serializers.py5
-rw-r--r--chat_api/views.py5
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
5class Dm(models.Model): 5class 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
23class Gm(models.Model): 23class 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
34class GmSimpleSerializer(serializers.ModelSerializer):
35 class Meta:
36 model = Gm
37 fields = '__all__'
38
34class GmSerializer(serializers.ModelSerializer): 39class 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
13from .models import * 13from .models import *
14from .serializers import * 14from .serializers import *
15from auth_api.serializers import UserSerializer
15 16
16 17
17def set_users(request): 18def 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