class InterfaceViewSet(ModelViewSet): queryset = Interface.objects.filter( virtual_machine__isnull=False).order_by( 'virtual_machine', CollateAsChar('_name')).prefetch_related('virtual_machine', 'tags') serializer_class = serializers.InterfaceSerializer filterset_class = filters.InterfaceFilterSet def get_serializer_class(self): request = self.get_serializer_context()['request'] if request.query_params.get('brief', False): # Override get_serializer_for_model(), which will return the DCIM NestedInterfaceSerializer return serializers.NestedInterfaceSerializer return serializers.InterfaceSerializer
class Meta: verbose_name = 'interface' ordering = ('virtual_machine', CollateAsChar('_name')) unique_together = ('virtual_machine', 'name')
class Meta: ordering = ('device', CollateAsChar('_name')) unique_together = ('device', 'name')
class Meta: # TODO: ordering and unique_together should include virtual_machine ordering = ('device', CollateAsChar('_name')) unique_together = ('device', 'name')