mirror of
https://github.com/netbox-community/netbox.git
synced 2024-05-10 07:54:54 +00:00
19 lines
689 B
Python
19 lines
689 B
Python
|
from rest_framework.metadata import SimpleMetadata
|
||
|
from django.utils.encoding import force_str
|
||
|
from utilities.api import ContentTypeField
|
||
|
|
||
|
|
||
|
class LimitedMetaData(SimpleMetadata):
|
||
|
|
||
|
def get_field_info(self, field):
|
||
|
field_info = super().get_field_info(field)
|
||
|
if hasattr(field, 'queryset') and not field_info.get('read_only') and isinstance(field, ContentTypeField):
|
||
|
field_info['choices'] = [
|
||
|
{
|
||
|
'value': choice_value,
|
||
|
'display_name': force_str(choice_name, strings_only=True)
|
||
|
}
|
||
|
for choice_value, choice_name in field.choices.items()
|
||
|
]
|
||
|
return field_info
|