delete files

This commit is contained in:
Anna Sudnitsina 2018-03-28 13:10:16 +03:00
parent 446842d2d4
commit 03c7c04ebb

View File

@ -9,12 +9,6 @@ import os
class Post(models.Model): class Post(models.Model):
name = models.CharField(max_length=30, blank=True) name = models.CharField(max_length=30, blank=True)
file = models.FileField(upload_to='images') file = models.FileField(upload_to='images')
def publish(self):
self.published_date = timezone.now()
self.save()
def __unicode__(self): def __unicode__(self):
return self.name return self.name
@ -30,3 +24,12 @@ class Post(models.Model):
return x return x
orig_name = property(orig_name) orig_name = property(orig_name)
def delete(self, *args, **kwargs):
# get file data
storage, path = self.file.storage, self.file.path
# delete model object
super(Post, self).delete(*args, **kwargs)
# delete files
storage.delete(path)
storage.delete("/thumb_".join(os.path.split(path)))