From 7b9d346d10f38ae0e06626386fad1f87d16dce9f Mon Sep 17 00:00:00 2001 From: Trupti Rajesh Kini Date: Fri, 17 Feb 2017 15:02:03 +0530 Subject: Fixed duplicate screenshots and chapters bug Fix will now overwrite existing file with the same name instead of renaming with characters.--- tbc/models.py | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) (limited to 'tbc') diff --git a/tbc/models.py b/tbc/models.py index 48c6952..a36d4ce 100644 --- a/tbc/models.py +++ b/tbc/models.py @@ -120,14 +120,14 @@ class OverwriteStorage(FileSystemStorage): def get_available_name(self, name): if self.exists(name): - os.remove(os.path.join("/Site/tbc-python_fossee_in/PythonTBC/Python-TBC-Interface/tbc/static/Python-Textbook-Companions/", name)) + os.remove(os.path.join(settings.MEDIA_ROOT, name)) return name fs = OverwriteStorage(location="/Site/tbc-python_fossee_in/PythonTBC/Python-TBC-Interface/tbc/static/Python-Textbook-Companions/") class Chapters(models.Model): name = models.CharField(max_length=200) - notebook = models.FileField(upload_to=get_notebook_dir) + notebook = models.FileField(storage=OverwriteStorage(), upload_to=get_notebook_dir) book = models.ForeignKey(Book) screen_shots = models.ManyToManyField('ScreenShots') def __unicode__(self): @@ -139,7 +139,7 @@ class Chapters(models.Model): class ScreenShots(models.Model): caption = models.CharField(max_length=128) - image = models.FileField(upload_to=get_image_dir) + image = models.FileField(storage=OverwriteStorage(), upload_to=get_image_dir) book = models.ForeignKey(Book) def __unicode__(self): name = self.caption or 'ScreenShots' @@ -174,7 +174,7 @@ class Proposal(models.Model): class SampleNotebook(models.Model): proposal = models.ForeignKey(Proposal) name = models.CharField(max_length=40) - sample_notebook = models.FileField(upload_to=get_sample_dir) + sample_notebook = models.FileField(storage=OverwriteStorage(), upload_to=get_sample_dir) def __unicode__(self): notebook = self.proposal.accepted.title or 'notebook' return '%s'%(notebook) -- cgit