class MediaInline(admin.TabularInline):
model = BookMedia
- readonly_fields = ['type', 'source_sha1']
+ readonly_fields = ['source_sha1']
extra = 0
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):
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)