Source code for pushnotifications.api.serializers

from rest_framework.relations import ManyRelatedField, PrimaryKeyRelatedField
from rest_framework.serializers import ModelSerializer

from pushnotifications.models import Device, Category, Message


[docs]class DeviceSerializer(ModelSerializer): receive_category = ManyRelatedField( allow_empty=True, required=False, child_relation=PrimaryKeyRelatedField( allow_empty=True, queryset=Category.objects.all(), required=False ), )
[docs] class Meta: model = Device fields = ( "pk", "registration_id", "active", "date_created", "type", "receive_category", ) read_only_fields = ("date_created",) extra_kwargs = {"active": {"default": True}}
[docs]class CategorySerializer(ModelSerializer):
[docs] class Meta: model = Category fields = ("key", "name", "description")
[docs]class MessageSerializer(ModelSerializer):
[docs] class Meta: model = Message fields = ("pk", "title", "body", "url", "category", "sent")