delete files
This commit is contained in:
parent
446842d2d4
commit
03c7c04ebb
@ -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)))
|
||||||
|
Loading…
Reference in New Issue
Block a user