I have a this model...
class MyModel(models.Model):
...
file = models.FileField(upload_to='files/',null=True, blank=True)
...
when i upload a file, example file name is docfile.doc
. when i change the file or i rewrite it and upload again docfile.doc
the file will become docfile_1.doc
and the old docfile.doc
is still exist.
i am doing the uploading and saving data in django-admin
my question is, how can i remove the old docfile.doc
if i upload the new docfile.doc
and the file name is still docfile.doc
?
can anyone help me in my case? thanks in advance
i try this one :
def content_file_name(instance, filename):
print instance
print filename
file = os.path.exists(filename)
print file
if file:
os.remove(filename)
return "file/"+str(filename)
class MyModel(models.Model):
...
file = models.FileField(upload_to=content_file_name,null=True, blank=True)
...
but nothing happend, when i upload docfile.doc
again, it will become docfile_1.doc
and the old docfile.doc
still exist.