X-Git-Url: https://git.mdrn.pl/wolnelektury.git/blobdiff_plain/6431b691f2335a3c614bfe153267bc5c58add51c..a408fadf10d71b8cf4d536a83e9f56e541d66db2:/apps/catalogue/fields.py 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):