-
Notifications
You must be signed in to change notification settings - Fork 2.9k
Closed
Labels
status: acceptedThis issue has been accepted for implementationThis issue has been accepted for implementationtype: housekeepingChanges to the application which do not directly impact the end userChanges to the application which do not directly impact the end user
Milestone
Description
Proposed Changes
Devise and implement a mechanism for filtering the content types for all user-facing models in NetBox. This includes essentially all of the models which can be manipulated directly via the UI or API, and excludes those "behind the scenes" models which cannot.
Justification
There are several instances where we currently work around this limitation. Below are some that I have identified; there are likely others to address as well.
- Retrieving content types for e.g. the object list dashboard widget:
# extras/dashboard/widgets.py
def get_content_type_labels():
return [
(content_type_identifier(ct), content_type_name(ct))
for ct in ContentType.objects.filter(
FeatureQuery('export_templates').get_query() | Q(app_label='extras', model='objectchange') |
Q(app_label='extras', model='configcontext')
).order_by('app_label', 'model')
]- Limiting
object_typechoices on CustomField import:
# extras/forms/bulk_import.py
class CustomFieldImportForm(CSVModelForm):
...
object_type = CSVContentTypeField(
label=_('Object type'),
queryset=ContentType.objects.all(),
limit_choices_to=FeatureQuery('custom_fields'), # Should be generic
required=False,
help_text=_("Object type (for object or multi-object fields)")
)- Filtering for SavedFilter objects:
# extras/forms/filtersets.py
class SavedFilterFilterForm(SavedFiltersMixin, FilterForm):
content_types = ContentTypeMultipleChoiceField(
label=_('Content types'),
queryset=ContentType.objects.filter(FeatureQuery('export_templates').get_query()), # Should be generic
required=False
)- Limiting
object_typechoices on CustomField edit:
# extras/forms/model_forms.py
class CustomFieldForm(BootstrapMixin, forms.ModelForm):
object_type = ContentTypeChoiceField(
label=_('Object type'),
queryset=ContentType.objects.all(),
# TODO: Come up with a canonical way to register suitable models
limit_choices_to=FeatureQuery('webhooks').get_query() | Q(app_label='auth', model__in=['user', 'group']),
required=False,
help_text=_("Type of the related object (for object/multi-object fields only)")
)Metadata
Metadata
Assignees
Labels
status: acceptedThis issue has been accepted for implementationThis issue has been accepted for implementationtype: housekeepingChanges to the application which do not directly impact the end userChanges to the application which do not directly impact the end user