X-Git-Url: https://git.mdrn.pl/wolnelektury.git/blobdiff_plain/6431b691f2335a3c614bfe153267bc5c58add51c..b1a76c6c9fe9f4fd4b9a47d3c4405b6484130977:/apps/catalogue/fields.py?ds=sidebyside diff --git a/apps/catalogue/fields.py b/apps/catalogue/fields.py index 510c06dac..048824498 100644 --- a/apps/catalogue/fields.py +++ b/apps/catalogue/fields.py @@ -122,9 +122,12 @@ class OverwritingFieldFile(FieldFile): def save(self, name, content, *args, **kwargs): leave = kwargs.pop('leave', None) - if not leave and self and content is not self: + # delete if there's a file already and there's a new one coming + if not leave and self and (not hasattr(content, 'path') or + content.path != self.path): self.delete(save=False) - return super(OverwritingFieldFile, self).save(name, content, *args, **kwargs) + return super(OverwritingFieldFile, self).save( + name, content, *args, **kwargs) class OverwritingFileField(models.FileField):