Fixes #11786: List only applicable object types in form widget when filtering custom fields

This commit is contained in:
jeremystretch 2023-02-19 16:17:57 -05:00
parent afc752b4ce
commit 315371bf7c
2 changed files with 7 additions and 12 deletions

View File

@ -19,6 +19,7 @@
* [#11683](https://github.com/netbox-community/netbox/issues/11683) - Fix CSV header attribute detection when auto-detecting import format * [#11683](https://github.com/netbox-community/netbox/issues/11683) - Fix CSV header attribute detection when auto-detecting import format
* [#11711](https://github.com/netbox-community/netbox/issues/11711) - Fix CSV import for multiple-object custom fields * [#11711](https://github.com/netbox-community/netbox/issues/11711) - Fix CSV import for multiple-object custom fields
* [#11723](https://github.com/netbox-community/netbox/issues/11723) - Circuit terminations should link to their associated circuits (rather than site or provider network) * [#11723](https://github.com/netbox-community/netbox/issues/11723) - Circuit terminations should link to their associated circuits (rather than site or provider network)
* [#11786](https://github.com/netbox-community/netbox/issues/11786) - List only applicable object types in form widget when filtering custom fields
--- ---

View File

@ -38,8 +38,7 @@ class CustomFieldFilterForm(SavedFiltersMixin, FilterForm):
('Attributes', ('type', 'content_type_id', 'group_name', 'weight', 'required', 'ui_visibility')), ('Attributes', ('type', 'content_type_id', 'group_name', 'weight', 'required', 'ui_visibility')),
) )
content_type_id = ContentTypeMultipleChoiceField( content_type_id = ContentTypeMultipleChoiceField(
queryset=ContentType.objects.all(), queryset=ContentType.objects.filter(FeatureQuery('custom_fields').get_query()),
limit_choices_to=FeatureQuery('custom_fields'),
required=False, required=False,
label=_('Object type') label=_('Object type')
) )
@ -79,8 +78,7 @@ class JobResultFilterForm(SavedFiltersMixin, FilterForm):
) )
obj_type = ContentTypeChoiceField( obj_type = ContentTypeChoiceField(
label=_('Object Type'), label=_('Object Type'),
queryset=ContentType.objects.all(), queryset=ContentType.objects.filter(FeatureQuery('job_results').get_query()),
limit_choices_to=FeatureQuery('job_results'), # TODO: This doesn't actually work
required=False, required=False,
) )
status = MultipleChoiceField( status = MultipleChoiceField(
@ -135,8 +133,7 @@ class CustomLinkFilterForm(SavedFiltersMixin, FilterForm):
('Attributes', ('content_types', 'enabled', 'new_window', 'weight')), ('Attributes', ('content_types', 'enabled', 'new_window', 'weight')),
) )
content_types = ContentTypeMultipleChoiceField( content_types = ContentTypeMultipleChoiceField(
queryset=ContentType.objects.all(), queryset=ContentType.objects.filter(FeatureQuery('custom_links').get_query()),
limit_choices_to=FeatureQuery('custom_links'),
required=False required=False
) )
enabled = forms.NullBooleanField( enabled = forms.NullBooleanField(
@ -162,8 +159,7 @@ class ExportTemplateFilterForm(SavedFiltersMixin, FilterForm):
('Attributes', ('content_types', 'mime_type', 'file_extension', 'as_attachment')), ('Attributes', ('content_types', 'mime_type', 'file_extension', 'as_attachment')),
) )
content_types = ContentTypeMultipleChoiceField( content_types = ContentTypeMultipleChoiceField(
queryset=ContentType.objects.all(), queryset=ContentType.objects.filter(FeatureQuery('export_templates').get_query()),
limit_choices_to=FeatureQuery('export_templates'),
required=False required=False
) )
mime_type = forms.CharField( mime_type = forms.CharField(
@ -187,8 +183,7 @@ class SavedFilterFilterForm(SavedFiltersMixin, FilterForm):
('Attributes', ('content_types', 'enabled', 'shared', 'weight')), ('Attributes', ('content_types', 'enabled', 'shared', 'weight')),
) )
content_types = ContentTypeMultipleChoiceField( content_types = ContentTypeMultipleChoiceField(
queryset=ContentType.objects.all(), queryset=ContentType.objects.filter(FeatureQuery('export_templates').get_query()),
limit_choices_to=FeatureQuery('export_templates'),
required=False required=False
) )
enabled = forms.NullBooleanField( enabled = forms.NullBooleanField(
@ -215,8 +210,7 @@ class WebhookFilterForm(SavedFiltersMixin, FilterForm):
('Events', ('type_create', 'type_update', 'type_delete')), ('Events', ('type_create', 'type_update', 'type_delete')),
) )
content_type_id = ContentTypeMultipleChoiceField( content_type_id = ContentTypeMultipleChoiceField(
queryset=ContentType.objects.all(), queryset=ContentType.objects.filter(FeatureQuery('webhooks').get_query()),
limit_choices_to=FeatureQuery('webhooks'),
required=False, required=False,
label=_('Object type') label=_('Object type')
) )