Exemple #1
0
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
Exemple #2
0
 class Meta:
     verbose_name = 'interface'
     ordering = ('virtual_machine', CollateAsChar('_name'))
     unique_together = ('virtual_machine', 'name')
Exemple #3
0
 class Meta:
     ordering = ('device', CollateAsChar('_name'))
     unique_together = ('device', 'name')
Exemple #4
0
 class Meta:
     # TODO: ordering and unique_together should include virtual_machine
     ordering = ('device', CollateAsChar('_name'))
     unique_together = ('device', 'name')