Add Document model method to check if a document exists in the storage backend

This commit is contained in:
Roberto Rosario
2011-02-06 22:44:16 -04:00
parent 1d70d68505
commit a3af46e25e
2 changed files with 6 additions and 3 deletions

View File

@@ -29,8 +29,7 @@ if FILESYSTEM_SLUGIFY_PATHS == False:
def get_filename_from_uuid(instance, filename, directory=STORAGE_DIRECTORY_NAME):
populate_file_extension_and_mimetype(instance, filename)
stem, extension = os.path.splitext(filename)
return '%s/%s%s' % (directory, instance.uuid, extension)
return '%s/%s' % (directory, instance.uuid)
def populate_file_extension_and_mimetype(instance, filename):
# First populate the file extension and mimetype
@@ -80,6 +79,9 @@ class Document(models.Model):
self.checksum = unicode(CHECKSUM_FUNCTION(self.file.read()))
if save:
self.save()
def exists(self):
return self.file.storage.exists(self.file.url)
def save(self, *args, **kwargs):
self.update_checksum(save=False)