Commit fe7f37a7 authored by Gijs Hendriksen's avatar Gijs Hendriksen

Add sent message overview to the push notifications API

parent 64067ce2
from rest_framework.relations import ManyRelatedField, PrimaryKeyRelatedField
from rest_framework.serializers import ModelSerializer
from pushnotifications.models import Device, Category
from pushnotifications.models import Device, Category, Message
class DeviceSerializer(ModelSerializer):
......@@ -35,3 +35,10 @@ class CategorySerializer(ModelSerializer):
model = Category
fields = ('key', 'name', 'description')
class MessageSerializer(ModelSerializer):
class Meta:
model = Message
fields = ('pk', 'title', 'body', 'url', 'category')
......@@ -4,4 +4,5 @@ from pushnotifications.api import viewsets
router = routers.SimpleRouter()
router.register(r'devices', viewsets.DeviceViewSet)
router.register(r'notifications', viewsets.MessageViewSet)
urlpatterns = router.urls
from django.utils.translation import get_language_from_request
from rest_framework import permissions
from rest_framework import permissions, viewsets
from rest_framework.decorators import action
from rest_framework.response import Response
from rest_framework.viewsets import ModelViewSet
from pushnotifications.api.permissions import IsOwner
from pushnotifications.api.serializers import (DeviceSerializer,
CategorySerializer)
from pushnotifications.models import Device, Category
CategorySerializer,
MessageSerializer)
from pushnotifications.models import Device, Category, Message
class DeviceViewSet(ModelViewSet):
class DeviceViewSet(viewsets.ModelViewSet):
permission_classes = (permissions.IsAuthenticated, IsOwner)
queryset = Device.objects.all()
serializer_class = DeviceSerializer
......@@ -47,3 +47,12 @@ class DeviceViewSet(ModelViewSet):
categories = Category.objects.all()
serializer = CategorySerializer(categories, many=True)
return Response(serializer.data)
class MessageViewSet(viewsets.ReadOnlyModelViewSet):
permission_classes = (permissions.IsAuthenticated,)
queryset = Message.objects.all()
serializer_class = MessageSerializer
def get_queryset(self):
return self.request.user.message_set.filter(sent=True)
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment