diff --git a/docs/release-notes/version-3.0.md b/docs/release-notes/version-3.0.md index ef99c4a0e..7a3005421 100644 --- a/docs/release-notes/version-3.0.md +++ b/docs/release-notes/version-3.0.md @@ -10,6 +10,7 @@ ### Bug Fixes * [#7701](https://github.com/netbox-community/netbox/issues/7701) - Fix conflation of assigned IP status & role in interface tables +* [#7741](https://github.com/netbox-community/netbox/issues/7741) - Fix 404 when attaching multiple images in succession * [#7752](https://github.com/netbox-community/netbox/issues/7752) - Fix minimum version check under Python v3.10 * [#7766](https://github.com/netbox-community/netbox/issues/7766) - Add missing outer dimension columns to rack table * [#7780](https://github.com/netbox-community/netbox/issues/7780) - Preserve mutli-line values during CSV file import diff --git a/netbox/extras/models/models.py b/netbox/extras/models/models.py index 75f5242d3..2c56f2f0f 100644 --- a/netbox/extras/models/models.py +++ b/netbox/extras/models/models.py @@ -357,6 +357,8 @@ class ImageAttachment(BigIDModel): objects = RestrictedQuerySet.as_manager() + clone_fields = ('content_type', 'object_id') + class Meta: ordering = ('name', 'pk') # name may be non-unique diff --git a/netbox/extras/views.py b/netbox/extras/views.py index d39f50c79..b0387c73d 100644 --- a/netbox/extras/views.py +++ b/netbox/extras/views.py @@ -475,11 +475,7 @@ class ImageAttachmentEditView(generic.ObjectEditView): def alter_obj(self, instance, request, args, kwargs): if not instance.pk: # Assign the parent object based on URL kwargs - try: - app_label, model = request.GET.get('content_type').split('.') - except (AttributeError, ValueError): - raise Http404("Content type not specified") - content_type = get_object_or_404(ContentType, app_label=app_label, model=model) + content_type = get_object_or_404(ContentType, pk=request.GET.get('content_type')) instance.parent = get_object_or_404(content_type.model_class(), pk=request.GET.get('object_id')) return instance diff --git a/netbox/templates/inc/image_attachments_panel.html b/netbox/templates/inc/image_attachments_panel.html index ca7312901..9706a7ffe 100644 --- a/netbox/templates/inc/image_attachments_panel.html +++ b/netbox/templates/inc/image_attachments_panel.html @@ -44,7 +44,7 @@ {% if perms.extras.add_imageattachment %}
diff --git a/netbox/utilities/templatetags/helpers.py b/netbox/utilities/templatetags/helpers.py index 1695c8257..5b5534321 100644 --- a/netbox/utilities/templatetags/helpers.py +++ b/netbox/utilities/templatetags/helpers.py @@ -6,6 +6,7 @@ from typing import Dict, Any import yaml from django import template from django.conf import settings +from django.contrib.contenttypes.models import ContentType from django.template.defaultfilters import date from django.urls import NoReverseMatch, reverse from django.utils import timezone @@ -78,6 +79,25 @@ def meta(obj, attr): return getattr(obj._meta, attr, '') +@register.filter() +def content_type(obj): + """ + Return the ContentType for the given object. + """ + return ContentType.objects.get_for_model(obj) + + +@register.filter() +def content_type_id(obj): + """ + Return the ContentType ID for the given object. + """ + content_type = ContentType.objects.get_for_model(obj) + if content_type: + return content_type.pk + return None + + @register.filter() def viewname(model, action): """