Django admin file upload with current model id

I ran into the same problem. Okm’s answer sent me on the right path but it seems to me it is possible to get the same functionality by just overriding the save() method of your Model.

def save(self, *args, **kwargs):
    if self.pk is None:
        saved_image = self.image
        self.image = None
        super(Material, self).save(*args, **kwargs)
        self.image = saved_image

    super(Material, self).save(*args, **kwargs)

This definitely saves the information correctly.

Leave a Comment