Skip to content

Commit

Permalink
Fix Source.DoesNotExist after migrating ImageField (#123)
Browse files Browse the repository at this point in the history
  • Loading branch information
JobDoesburg authored Jul 24, 2024
1 parent 4970206 commit 13fe83f
Showing 1 changed file with 6 additions and 1 deletion.
7 changes: 6 additions & 1 deletion thumbnails/backends/metadata.py
Original file line number Diff line number Diff line change
Expand Up @@ -76,7 +76,12 @@ def get_thumbnail(self, source_name, size):
return None

def add_thumbnail(self, source_name, size, name):
source = self.get_source(source_name)
try:
source = self.get_source(source_name)
except Source.DoesNotExist:
# If the source doesn't exist, create it
# For example when migrating from a regular ImageField to a thumbnailed ImageField
source = self.add_source(source_name)
meta = ThumbnailMeta.objects.create(source=source, size=size, name=name)
return ImageMeta(source_name, meta.name, meta.size)

Expand Down

0 comments on commit 13fe83f

Please sign in to comment.