Reputation: 4008
The user has the possibility to add/delete image and documents.
I used GCBV UpdateView and a FormModel for this.
How can I offer the possibility to the user to delete the file/image ?
Upvotes: 0
Views: 1063
Reputation: 3386
You will have to override the delete method of your model.
class YourModel(models.Model):
file_field = models.FileField(upload_to='folder')
def delete(self):
os.remove(settings.MEDIA_ROOT+'folder/'+self.file_field.path)
return super(YourModel,self).delete()
This will delete the entry from the model and also delete the file from your system.
Upvotes: 3