diff options
author | jdlugosz963 <jdlugosz963@gmail.com> | 2021-11-26 18:44:38 +0100 |
---|---|---|
committer | jdlugosz963 <jdlugosz963@gmail.com> | 2021-11-26 18:44:38 +0100 |
commit | eaf89ff64ce5c4e39239aec50a973d1c58a40bee (patch) | |
tree | 161c53033c08f9f0bb499dd3c1f394a0f508cf4e /chat_api/views.py | |
parent | 45daed0c4fd60febf9458c889f7a89c0e5ab70bd (diff) | |
download | lom_api-eaf89ff64ce5c4e39239aec50a973d1c58a40bee.tar.gz lom_api-eaf89ff64ce5c4e39239aec50a973d1c58a40bee.zip |
add groups views
Diffstat (limited to 'chat_api/views.py')
-rw-r--r-- | chat_api/views.py | 29 |
1 files changed, 27 insertions, 2 deletions
diff --git a/chat_api/views.py b/chat_api/views.py index 91ea44a..f94f3a0 100644 --- a/chat_api/views.py +++ b/chat_api/views.py | |||
@@ -1,3 +1,28 @@ | |||
1 | from django.shortcuts import render | 1 | from django.db.models.query import QuerySet |
2 | from django.http.response import Http404 | ||
3 | from rest_framework.response import Response | ||
4 | from rest_framework.serializers import Serializer | ||
5 | from rest_framework.views import APIView | ||
6 | from rest_framework import permissions | ||
7 | from rest_framework import generics | ||
8 | from knox.auth import TokenAuthentication | ||
2 | 9 | ||
3 | # Create your views here. | 10 | from django.db.models.query import Q |
11 | |||
12 | from .models import * | ||
13 | from .serializers import * | ||
14 | |||
15 | class GroupView(generics.ListCreateAPIView): | ||
16 | permission_classes = (permissions.IsAuthenticated, ) | ||
17 | authentication_classes = (TokenAuthentication, ) | ||
18 | serializer_class = GroupSerializer | ||
19 | |||
20 | def get_queryset(self): | ||
21 | return Group.objects.filter( | ||
22 | Q(owner=self.request.user) | | ||
23 | Q(users__in=(self.request.user, )) | ||
24 | ).distinct() | ||
25 | |||
26 | def create(self, request, *args, **kwargs): | ||
27 | request.data['owner'] = request.user.pk | ||
28 | return super().create(request, *args, **kwargs) \ No newline at end of file | ||