From 32e27db91137094ff6b8ebb4154cb44addb837e2 Mon Sep 17 00:00:00 2001 From: Radek Czajka Date: Wed, 31 Aug 2011 12:23:37 +0200 Subject: [PATCH] media upload fix --- apps/catalogue/admin.py | 2 +- apps/catalogue/fields.py | 6 +++--- apps/catalogue/models.py | 2 +- 3 files changed, 5 insertions(+), 5 deletions(-) diff --git a/apps/catalogue/admin.py b/apps/catalogue/admin.py index 32c8f8c71..22cf15fa4 100644 --- a/apps/catalogue/admin.py +++ b/apps/catalogue/admin.py @@ -21,7 +21,7 @@ class TagAdmin(admin.ModelAdmin): class MediaInline(admin.TabularInline): model = BookMedia - readonly_fields = ['type', 'source_sha1'] + readonly_fields = ['source_sha1'] extra = 0 diff --git a/apps/catalogue/fields.py b/apps/catalogue/fields.py index 4de2e7cb6..e11d611e5 100644 --- a/apps/catalogue/fields.py +++ b/apps/catalogue/fields.py @@ -133,11 +133,11 @@ class OverwritingFieldFile(FieldFile): Deletes the old file before saving the new one. """ - def save(self, *args, **kwargs): + def save(self, name, content, *args, **kwargs): leave = kwargs.pop('leave', None) - if not leave and self: + if not leave and self and content is not self: self.delete(save=False) - return super(OverwritingFieldFile, self).save(*args, **kwargs) + return super(OverwritingFieldFile, self).save(name, content, *args, **kwargs) class OverwritingFileField(models.FileField): diff --git a/apps/catalogue/models.py b/apps/catalogue/models.py index fd5dc987a..272228627 100644 --- a/apps/catalogue/models.py +++ b/apps/catalogue/models.py @@ -188,7 +188,7 @@ def book_upload_path(ext=None, maxlen=100): class BookMedia(models.Model): - type = models.CharField(_('type'), choices=MEDIA_FORMATS, max_length="100", editable=False) + type = models.CharField(_('type'), choices=MEDIA_FORMATS, max_length="100") name = models.CharField(_('name'), max_length="100") file = OverwritingFileField(_('file'), upload_to=book_upload_path()) uploaded_at = models.DateTimeField(_('creation date'), auto_now_add=True, editable=False) -- 2.20.1