Reputation: 253
This is an admin form handler, for example I upload a test.txt
file in the django admin panel:
def save_model(self, request, obj, form, change):
if 'file' in form.changed_data:
print("file has changed: ")
print(obj.file)
else:
print("file has not changed")
super(FileAdmin, self).save_model(request, obj, form, change)
here I get the original file name from the upload form, but by fact the file is saved with another name if there is already a file with this name, but in the above code i get only the original name in all cases, how to can I get the changed/updated file name that was saved?..
Upvotes: 0
Views: 208
Reputation: 77942
The "_somehash" part is added by your project's filestorage when he sees there's already a file by the same name in the destination directory. This happens when the model instance is saved, so if all you need is to read the "final" name, you can get it from your (saved) model field's .name
attribute (I assume you use a FileField of course).
Upvotes: 1