-
Notifications
You must be signed in to change notification settings - Fork 5
/
Copy pathserializers.py
81 lines (71 loc) · 2.47 KB
/
serializers.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
from rest_framework import serializers
from api.serializers import (
MiniCountrySerializer,
MiniEventSerializer,
SurgeEventSerializer,
)
from deployments.serializers import MolnixTagSerializer
from lang.serializers import ModelSerializer
from .models import Subscription, SurgeAlert
class SurgeAlertSerializer(ModelSerializer):
event = SurgeEventSerializer(required=False)
country = MiniCountrySerializer(required=False)
atype_display = serializers.CharField(source="get_atype_display", read_only=True)
molnix_status_display = serializers.CharField(source="get_molnix_status_display", read_only=True)
category_display = serializers.CharField(source="get_category_display", read_only=True)
molnix_tags = MolnixTagSerializer(many=True, read_only=True)
class Meta:
model = SurgeAlert
fields = (
"operation",
"country",
"message",
"deployment_needed",
"is_private",
"event",
"created_at",
"id",
"atype",
"atype_display",
"category",
"category_display",
"molnix_id",
"molnix_tags",
"molnix_status",
"opens",
"closes",
"start",
"end",
"molnix_status",
"molnix_status_display",
)
# class UnauthenticatedSurgeAlertSerializer(ModelSerializer):
# event = MiniEventSerializer()
# atype_display = serializers.CharField(source='get_atype_display', read_only=True)
# category_display = serializers.CharField(source='get_category_display', read_only=True)
#
# class Meta:
# model = SurgeAlert
# fields = (
# 'operation', 'deployment_needed', 'is_private', 'event', 'created_at', 'id',
# 'atype', 'atype_display', 'category', 'category_display', 'is_active',
# )
class SubscriptionSerializer(ModelSerializer):
country = MiniCountrySerializer()
event = MiniEventSerializer()
stype_display = serializers.CharField(source="get_stype_display", read_only=True)
rtype_display = serializers.CharField(source="get_rtype_display", read_only=True)
class Meta:
model = Subscription
fields = (
"user",
"country",
"region",
"event",
"dtype",
"lookup_id",
"stype",
"stype_display",
"rtype",
"rtype_display",
)