mirror of
https://github.com/netbox-community/netbox.git
synced 2024-05-10 07:54:54 +00:00
* Introduce RelatedObjectCountField * Introduce get_annotations_for_serializer() and enable dynamic annotations * Add RelatedObjectCountFields to serializers; remove static annotations from querysets * Remove annotations cleanup logic from BriefModeMixin * Annotate type for RelatedObjectCountField * Remove redundant field on TagSerializer * Add missing reverse relationship for power feeds to rack * Refactor RelatedObjectCountField to take a single relationship name
This commit is contained in:
@@ -2,7 +2,7 @@ from rest_framework import serializers
|
||||
|
||||
from core.choices import *
|
||||
from core.models import *
|
||||
from netbox.api.fields import ChoiceField, ContentTypeField
|
||||
from netbox.api.fields import ChoiceField, ContentTypeField, RelatedObjectCountField
|
||||
from netbox.api.serializers import BaseModelSerializer, NetBoxModelSerializer
|
||||
from netbox.utils import get_data_backend_choices
|
||||
from users.api.nested_serializers import NestedUserSerializer
|
||||
@@ -28,9 +28,7 @@ class DataSourceSerializer(NetBoxModelSerializer):
|
||||
)
|
||||
|
||||
# Related object counts
|
||||
file_count = serializers.IntegerField(
|
||||
read_only=True
|
||||
)
|
||||
file_count = RelatedObjectCountField('datafiles')
|
||||
|
||||
class Meta:
|
||||
model = DataSource
|
||||
|
@@ -9,7 +9,6 @@ from rest_framework.viewsets import ReadOnlyModelViewSet
|
||||
from core import filtersets
|
||||
from core.models import *
|
||||
from netbox.api.viewsets import NetBoxModelViewSet, NetBoxReadOnlyModelViewSet
|
||||
from utilities.utils import count_related
|
||||
from . import serializers
|
||||
|
||||
|
||||
@@ -22,9 +21,7 @@ class CoreRootView(APIRootView):
|
||||
|
||||
|
||||
class DataSourceViewSet(NetBoxModelViewSet):
|
||||
queryset = DataSource.objects.annotate(
|
||||
file_count=count_related(DataFile, 'source')
|
||||
)
|
||||
queryset = DataSource.objects.all()
|
||||
serializer_class = serializers.DataSourceSerializer
|
||||
filterset_class = filtersets.DataSourceFilterSet
|
||||
|
||||
|
Reference in New Issue
Block a user