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