good day everyone, i am a self learner and quite new to django and i am facing some questions currently, i created a model which will have images upload to a self-defined directory as like this:
class OverwriteStorage(FileSystemStorage):
def get_available_name(self, name, max_length=None):
self.delete(name)
return name
class DealerList(models.Model):
def user_dir_folder(instance, filename):
return 'dealerImg/{0}/{1}'.format(instance.dealerCompanyName, filename)
dealerCompanyName = models.CharField(max_length=100)
Cert = models.ImageField(storage=OverwriteStorage(), upload_to=user_dir_folder)
Img = models.ImageField(storage=OverwriteStorage(), upload_to=user_dir_folder)
and i installed ‘django_cleanup.apps.CleanupConfig’ into the settings file to cleanup those related files in case if an instance is deleted (but the empty folder stay existed which i dont know how to deal with yet, but this is second question).
now what i am facing is, if an instance’s ‘dealerCompanyName’ field is updated, the folder which created named with the ‘dealerCompanyName’ won’t get updated along (also django will delete those uploaded files that cant match any instance now after ‘dealerCompanyName’ is updated since i installed cleanup, but this is the third question), what i wanna ask is, is there anyway to update that folder’s name too if ‘dealerCompanyName’ field get updated? by the way if there are answer for the second and third questions mentioned above will be very very appreciated since i will face them very soon. Hopefully could get some solutions since i have tried for long time but none is working. Many Thanks!