1
0
mirror of https://github.com/netbox-community/netbox.git synced 2024-05-10 07:54:54 +00:00

Renamed ChoiceFieldSerializer and ContentTypeFieldSerializer

This commit is contained in:
Jeremy Stretch
2018-07-30 12:41:20 -04:00
parent 838af2b2d8
commit c2416411c1
7 changed files with 35 additions and 36 deletions

View File

@@ -63,7 +63,6 @@ class TagField(RelatedField):
"""
Represent a writable list of Tags associated with an object (use with many=True).
"""
def to_internal_value(self, data):
obj = self.parent.parent.instance
content_type = ContentType.objects.get_for_model(obj)
@@ -74,7 +73,7 @@ class TagField(RelatedField):
return value.name
class ChoiceFieldSerializer(Field):
class ChoiceField(Field):
"""
Represent a ChoiceField as {'value': <DB value>, 'label': <string>}.
"""
@@ -87,7 +86,7 @@ class ChoiceFieldSerializer(Field):
self._choices[k2] = v2
else:
self._choices[k] = v
super(ChoiceFieldSerializer, self).__init__(**kwargs)
super(ChoiceField, self).__init__(**kwargs)
def to_representation(self, obj):
return {'value': obj, 'label': self._choices[obj]}
@@ -96,7 +95,7 @@ class ChoiceFieldSerializer(Field):
return data
class ContentTypeFieldSerializer(Field):
class ContentTypeField(Field):
"""
Represent a ContentType as '<app_label>.<model>'
"""

View File

@@ -3,7 +3,7 @@ from drf_yasg.inspectors import FieldInspector, NotHandled, PaginatorInspector,
from rest_framework.fields import ChoiceField
from extras.api.customfields import CustomFieldsSerializer
from utilities.api import ChoiceFieldSerializer
from utilities.api import ChoiceField
class CustomChoiceFieldInspector(FieldInspector):
@@ -12,7 +12,7 @@ class CustomChoiceFieldInspector(FieldInspector):
# https://drf-yasg.readthedocs.io/en/stable/_modules/drf_yasg/inspectors/base.html#FieldInspector._get_partial_types
SwaggerType, _ = self._get_partial_types(field, swagger_object_type, use_references, **kwargs)
if isinstance(field, ChoiceFieldSerializer):
if isinstance(field, ChoiceField):
value_schema = openapi.Schema(type=openapi.TYPE_INTEGER)
choices = list(field._choices.keys())