I\'m trying to create a simple photo gallery with the default Django admin. I\'d like to save a sample photo for each gallery, but I don\'t want to keep the filname. Instead
For Django 2.2, follow the below code.
def save(self, *args, **kwargs):
if self.pk is None:
saved_image = self.image
self.image = None
super(Gallery, self).save(*args, **kwargs)
self.image = saved_image
if 'force_insert' in kwargs:
kwargs.pop('force_insert')
super(Gallery, self).save(*args, **kwargs)
Add the above code snippet to your 'class Gallery'.
P.S.: This will work for DRF as well when you save via views.py. Note that second if (condition) is required for DRF.