Skip to content

Commit 7fca630

Browse files
committed
deleting old model after creating a new one
1 parent 3f083da commit 7fca630

1 file changed

Lines changed: 3 additions & 0 deletions

File tree

files/migrations/0006_auto_20230929_1727.py

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -38,6 +38,7 @@ def migration(apps, schema_editor):
3838
for i in files:
3939
# get all files that end in a .png or .jpg
4040
if i.link.endswith(".png") or i.link.endswith(".jpg"):
41+
old_link = i.link
4142
# convert .png/.jpg to .webp
4243
# download file and convert it to PIL image
4344
file = requests.get(i.link)
@@ -63,6 +64,8 @@ def migration(apps, schema_editor):
6364
i.extension = "webp"
6465
i.mime_type = "image/webp"
6566
i.save()
67+
# delete the one with the old url
68+
UserFile.objects.get(link=old_link).delete()
6669

6770

6871
class Migration(migrations.Migration):

0 commit comments

Comments
 (0)