I have a Django model with multiple ImageFields.
On the ModelAdmin class I've set save_as = True
, which means The admin page has a "Save as new" button, which allows for duplicating an existing item and saving it as new.
However when this button is used, the ImageFields are not duplicated and are left blank on the new item.
Looking at the POST request, I see that these fields are blank in the post data.
I've thought about overriding the Model class' save method, and copying the images from the old object by myself. But as far as I could figure out, I have no way to tell that the object is saved "as new". I also don't seem to have the ID of the old Item so I cannot get the old Images from it.
Is there a way to get these image fields to be duplicated as well?
Edit: Added Example code by request.
Created a minimalistic app with only one model. Verified problem still occurs.
Sample models.py:
from django.db import models
class Person(models.Model):
face_image = models.ImageField(upload_to='images',
null=False,
blank=True)
Sample admin.py:
from django.contrib import admin
from testapp.models import Person
class PersonAdmin(admin.ModelAdmin):
save_as = True
admin.site.register(Person, PersonAdmin)