mirror of
https://github.com/netbox-community/netbox.git
synced 2024-05-10 07:54:54 +00:00
Enable brief API output utilizing nested serializers
This commit is contained in:
@ -82,7 +82,7 @@ $(document).ready(function() {
|
||||
}
|
||||
|
||||
if ($(parent).val() || $(parent).attr('nullable') == 'true') {
|
||||
var api_url = child_field.attr('api-url') + '&limit=0';
|
||||
var api_url = child_field.attr('api-url') + '&limit=0&brief';
|
||||
var disabled_indicator = child_field.attr('disabled-indicator');
|
||||
var initial_value = child_field.attr('initial');
|
||||
var display_field = child_field.attr('display-field') || 'name';
|
||||
|
@ -192,6 +192,19 @@ class ModelViewSet(_ModelViewSet):
|
||||
|
||||
return super(ModelViewSet, self).get_serializer(*args, **kwargs)
|
||||
|
||||
def get_serializer_class(self):
|
||||
|
||||
# If 'brief' has been passed as a query param, find and return the nested serializer for this model, if one
|
||||
# exists
|
||||
request = self.get_serializer_context()['request']
|
||||
if 'brief' in request.query_params:
|
||||
serializer_class = get_serializer_for_model(self.queryset.model, prefix='Nested')
|
||||
if serializer_class is not None:
|
||||
return serializer_class
|
||||
|
||||
# Fall back to the hard-coded serializer class
|
||||
return self.serializer_class
|
||||
|
||||
|
||||
class FieldChoicesViewSet(ViewSet):
|
||||
"""
|
||||
|
Reference in New Issue
Block a user