1
1
from django .contrib .auth import get_user_model
2
- from django .contrib .contenttypes .models import ContentType
3
2
from django .core .exceptions import ObjectDoesNotExist
4
3
from rest_framework import serializers
5
4
6
5
from core .api .serializers import JobSerializer
7
6
from core .api .nested_serializers import NestedDataSourceSerializer , NestedDataFileSerializer , NestedJobSerializer
7
+ from core .models import ContentType
8
8
from dcim .api .nested_serializers import (
9
9
NestedDeviceRoleSerializer , NestedDeviceTypeSerializer , NestedLocationSerializer , NestedPlatformSerializer ,
10
10
NestedRegionSerializer , NestedSiteSerializer , NestedSiteGroupSerializer ,
14
14
from drf_spectacular .types import OpenApiTypes
15
15
from extras .choices import *
16
16
from extras .models import *
17
- from extras .utils import FeatureQuery
18
17
from netbox .api .exceptions import SerializerNotFound
19
18
from netbox .api .fields import ChoiceField , ContentTypeField , SerializedPKRelatedField
20
19
from netbox .api .serializers import BaseModelSerializer , NetBoxModelSerializer , ValidatedModelSerializer
64
63
class WebhookSerializer (NetBoxModelSerializer ):
65
64
url = serializers .HyperlinkedIdentityField (view_name = 'extras-api:webhook-detail' )
66
65
content_types = ContentTypeField (
67
- queryset = ContentType .objects .filter ( FeatureQuery ( 'webhooks' ). get_query () ),
66
+ queryset = ContentType .objects .with_feature ( 'webhooks' ),
68
67
many = True
69
68
)
70
69
@@ -85,7 +84,7 @@ class Meta:
85
84
class CustomFieldSerializer (ValidatedModelSerializer ):
86
85
url = serializers .HyperlinkedIdentityField (view_name = 'extras-api:customfield-detail' )
87
86
content_types = ContentTypeField (
88
- queryset = ContentType .objects .filter ( FeatureQuery ( 'custom_fields' ). get_query () ),
87
+ queryset = ContentType .objects .with_feature ( 'custom_fields' ),
89
88
many = True
90
89
)
91
90
type = ChoiceField (choices = CustomFieldTypeChoices )
@@ -151,7 +150,7 @@ class Meta:
151
150
class CustomLinkSerializer (ValidatedModelSerializer ):
152
151
url = serializers .HyperlinkedIdentityField (view_name = 'extras-api:customlink-detail' )
153
152
content_types = ContentTypeField (
154
- queryset = ContentType .objects .filter ( FeatureQuery ( 'custom_links' ). get_query () ),
153
+ queryset = ContentType .objects .with_feature ( 'custom_links' ),
155
154
many = True
156
155
)
157
156
@@ -170,7 +169,7 @@ class Meta:
170
169
class ExportTemplateSerializer (ValidatedModelSerializer ):
171
170
url = serializers .HyperlinkedIdentityField (view_name = 'extras-api:exporttemplate-detail' )
172
171
content_types = ContentTypeField (
173
- queryset = ContentType .objects .filter ( FeatureQuery ( 'export_templates' ). get_query () ),
172
+ queryset = ContentType .objects .with_feature ( 'export_templates' ),
174
173
many = True
175
174
)
176
175
data_source = NestedDataSourceSerializer (
@@ -215,7 +214,7 @@ class Meta:
215
214
class BookmarkSerializer (ValidatedModelSerializer ):
216
215
url = serializers .HyperlinkedIdentityField (view_name = 'extras-api:bookmark-detail' )
217
216
object_type = ContentTypeField (
218
- queryset = ContentType .objects .filter ( FeatureQuery ( 'bookmarks' ). get_query () ),
217
+ queryset = ContentType .objects .with_feature ( 'bookmarks' ),
219
218
)
220
219
object = serializers .SerializerMethodField (read_only = True )
221
220
user = NestedUserSerializer ()
@@ -239,7 +238,7 @@ def get_object(self, instance):
239
238
class TagSerializer (ValidatedModelSerializer ):
240
239
url = serializers .HyperlinkedIdentityField (view_name = 'extras-api:tag-detail' )
241
240
object_types = ContentTypeField (
242
- queryset = ContentType .objects .filter ( FeatureQuery ( 'tags' ). get_query () ),
241
+ queryset = ContentType .objects .with_feature ( 'tags' ),
243
242
many = True ,
244
243
required = False
245
244
)
0 commit comments