mirror of
https://github.com/netbox-community/netbox.git
synced 2025-08-26 09:16:10 -06:00
9608 fix choices
This commit is contained in:
parent
7df7db0b64
commit
5b941c9809
@ -686,7 +686,7 @@ class DeviceSerializer(NetBoxModelSerializer):
|
||||
|
||||
|
||||
class DeviceWithConfigContextSerializer(DeviceSerializer):
|
||||
config_context = serializers.SerializerMethodField()
|
||||
config_context = serializers.SerializerMethodField(read_only=True)
|
||||
|
||||
class Meta(DeviceSerializer.Meta):
|
||||
fields = [
|
||||
@ -1168,19 +1168,15 @@ class PowerFeedSerializer(NetBoxModelSerializer, CabledObjectSerializer, Connect
|
||||
)
|
||||
type = ChoiceField(
|
||||
choices=PowerFeedTypeChoices,
|
||||
default=PowerFeedTypeChoices.TYPE_PRIMARY
|
||||
)
|
||||
status = ChoiceField(
|
||||
choices=PowerFeedStatusChoices,
|
||||
default=PowerFeedStatusChoices.STATUS_ACTIVE
|
||||
)
|
||||
supply = ChoiceField(
|
||||
choices=PowerFeedSupplyChoices,
|
||||
default=PowerFeedSupplyChoices.SUPPLY_AC
|
||||
)
|
||||
phase = ChoiceField(
|
||||
choices=PowerFeedPhaseChoices,
|
||||
default=PowerFeedPhaseChoices.PHASE_SINGLE
|
||||
)
|
||||
|
||||
class Meta:
|
||||
|
@ -1436,10 +1436,10 @@ class PowerFeedTypeChoices(ChoiceSet):
|
||||
TYPE_PRIMARY = 'primary'
|
||||
TYPE_REDUNDANT = 'redundant'
|
||||
|
||||
CHOICES = (
|
||||
CHOICES = [
|
||||
(TYPE_PRIMARY, 'Primary', 'green'),
|
||||
(TYPE_REDUNDANT, 'Redundant', 'cyan'),
|
||||
)
|
||||
]
|
||||
|
||||
|
||||
class PowerFeedSupplyChoices(ChoiceSet):
|
||||
|
@ -14,7 +14,7 @@ __all__ = (
|
||||
)
|
||||
|
||||
|
||||
@extend_schema_field(OpenApiTypes.OBJECT)
|
||||
@extend_schema_field(OpenApiTypes.STR)
|
||||
class ChoiceField(serializers.Field):
|
||||
"""
|
||||
Represent a ChoiceField as {'value': <DB value>, 'label': <string>}. Accepts a single value on write.
|
||||
|
@ -1,4 +1,5 @@
|
||||
from django.contrib.auth.models import ContentType
|
||||
from drf_spectacular.types import OpenApiTypes
|
||||
from drf_spectacular.utils import extend_schema_field
|
||||
from rest_framework import serializers
|
||||
|
||||
@ -98,7 +99,7 @@ class ContactAssignmentSerializer(NetBoxModelSerializer):
|
||||
object = serializers.SerializerMethodField(read_only=True)
|
||||
contact = NestedContactSerializer()
|
||||
role = NestedContactRoleSerializer(required=False, allow_null=True)
|
||||
priority = ChoiceField(choices=ContactPriorityChoices, allow_blank=True, required=False, default='')
|
||||
priority = extend_schema_field(OpenApiTypes.STR)(ChoiceField(choices=ContactPriorityChoices, allow_blank=True, required=False, default=''))
|
||||
|
||||
class Meta:
|
||||
model = ContactAssignment
|
||||
@ -107,7 +108,7 @@ class ContactAssignmentSerializer(NetBoxModelSerializer):
|
||||
'last_updated',
|
||||
]
|
||||
|
||||
@extend_schema_field(serializers.JSONField(allow_null=True))
|
||||
@extend_schema_field(OpenApiTypes.OBJECT)
|
||||
def get_object(self, instance):
|
||||
serializer = get_serializer_for_model(instance.content_type.model_class(), prefix=NESTED_SERIALIZER_PREFIX)
|
||||
context = {'request': self.context['request']}
|
||||
|
Loading…
Reference in New Issue
Block a user