Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

#15548 - False Positive Related Object in Custom Fields #15705

Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion netbox/extras/views.py
Original file line number Diff line number Diff line change
Expand Up @@ -69,7 +69,7 @@ class CustomFieldEditView(generic.ObjectEditView):


@register_model_view(CustomField, 'delete')
class CustomFieldDeleteView(generic.ObjectDeleteView):
class CustomFieldDeleteView(generic.CustomObjectDeleteView):
queryset = CustomField.objects.select_related('choice_set')


Expand Down
38 changes: 38 additions & 0 deletions netbox/netbox/views/generic/object_views.py
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@
'ObjectDeleteView',
'ObjectEditView',
'ObjectView',
'CustomObjectDeleteView',
)


Expand Down Expand Up @@ -557,3 +558,40 @@ def post(self, request):
'form': form,
'return_url': self.get_return_url(request),
})


class CustomObjectDeleteView(ObjectDeleteView):
"""
Custom delete a single object. It returns empty dependent_objects to avoid show message about dependent objects.
"""

def get(self, request, *args, **kwargs):
"""
GET request handler.

Override the get method to return an empty dependent_objects dictionary.
"""

obj = self.get_object(**kwargs)
form = ConfirmationForm(initial=request.GET)
dependent_objects = {}

if is_htmx(request):
viewname = get_viewname(self.queryset.model, action='delete')
form_url = reverse(viewname, kwargs={'pk': obj.pk})
return render(request, 'htmx/delete_form.html', {
'object': obj,
'object_type': self.queryset.model._meta.verbose_name,
'form': form,
'form_url': form_url,
'dependent_objects': dependent_objects,
**self.get_extra_context(request, obj),
})

return render(request, self.template_name, {
'object': obj,
'form': form,
'return_url': self.get_return_url(request, obj),
'dependent_objects': dependent_objects,
**self.get_extra_context(request, obj),
})
Loading