-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathserializers.py
More file actions
38 lines (31 loc) · 1.13 KB
/
serializers.py
File metadata and controls
38 lines (31 loc) · 1.13 KB
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
from rest_framework import serializers
from fullctl.django.rest.serializers import ModelSerializer
from fullctl.django.rest.decorators import serializer_registry
from django_prefixctl.rest.serializers.monitor import (
register_prefix_monitor,
MonitorCreationMixin,
)
import monitor_example.models as models
Serializers, register = serializer_registry()
# register the monitor with prefixctl
@register_prefix_monitor
# add the monitor to the serializer registry, afterwards it
# will be available as Serializers.example_monitor, purely for convenience
@register
class ExampleMonitor(MonitorCreationMixin, ModelSerializer):
"""
A bare minimum monitor REST serializer for our example monitor.
"""
# set the monitor type choices and default
# to the reference tag of the monitor model
monitor_type = serializers.ChoiceField(
choices=["example_monitor"], default="example_monitor"
)
instance = serializers.PrimaryKeyRelatedField(read_only=True)
class Meta:
model = models.ExampleMonitor
fields = [
"instance",
"prefix_set",
"monitor_type",
]