Procházet zdrojové kódy

Fixes #8976: Add missing object_type field on CustomField REST API serializer

jeremystretch před 3 roky
rodič
revize
227bac7c60

+ 1 - 0
docs/release-notes/version-3.2.md

@@ -152,6 +152,7 @@ Where it is desired to limit the range of available VLANs within a group, users
 * [#8869](https://github.com/netbox-community/netbox/issues/8869) - Fix NoReverseMatch exception when displaying tag w/assignments
 * [#8872](https://github.com/netbox-community/netbox/issues/8872) - Enable filtering by custom object fields
 * [#8970](https://github.com/netbox-community/netbox/issues/8970) - Permit nested inventory item templates on device types
+* [#8976](https://github.com/netbox-community/netbox/issues/8976) - Add missing `object_type` field on CustomField REST API serializer
 
 ### Other Changes
 

+ 6 - 3
netbox/extras/api/serializers.py

@@ -78,15 +78,18 @@ class CustomFieldSerializer(ValidatedModelSerializer):
         many=True
     )
     type = ChoiceField(choices=CustomFieldTypeChoices)
+    object_type = ContentTypeField(
+        queryset=ContentType.objects.all()
+    )
     filter_logic = ChoiceField(choices=CustomFieldFilterLogicChoices, required=False)
     data_type = serializers.SerializerMethodField()
 
     class Meta:
         model = CustomField
         fields = [
-            'id', 'url', 'display', 'content_types', 'type', 'data_type', 'name', 'label', 'description', 'required',
-            'filter_logic', 'default', 'weight', 'validation_minimum', 'validation_maximum', 'validation_regex',
-            'choices', 'created', 'last_updated',
+            'id', 'url', 'display', 'content_types', 'type', 'object_type', 'data_type', 'name', 'label', 'description',
+            'required', 'filter_logic', 'default', 'weight', 'validation_minimum', 'validation_maximum',
+            'validation_regex', 'choices', 'created', 'last_updated',
         ]
 
     def get_data_type(self, obj):

+ 4 - 0
netbox/extras/forms/models.py

@@ -48,6 +48,10 @@ class CustomFieldForm(BootstrapMixin, forms.ModelForm):
     class Meta:
         model = CustomField
         fields = '__all__'
+        help_texts = {
+            'type': "The type of data stored in this field. For object/multi-object fields, select the related object "
+                    "type below."
+        }
         widgets = {
             'type': StaticSelect(),
             'filter_logic': StaticSelect(),