Fixes #7741: Fix 404 when attaching multiple images in succession

This commit is contained in:
jeremystretch
2021-11-09 16:46:58 -05:00
parent 9f0f4868e0
commit 1b858c2f2f
5 changed files with 25 additions and 6 deletions

View File

@@ -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

View File

@@ -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