File tree Expand file tree Collapse file tree 1 file changed +37
-0
lines changed
bullet/gallery/migrations Expand file tree Collapse file tree 1 file changed +37
-0
lines changed Original file line number Diff line number Diff line change 1+ # Generated by Django 5.1.5 on 2025-06-03 09:58
2+
3+ import shutil
4+ from pathlib import Path
5+ from typing import TYPE_CHECKING
6+
7+ from django .db import migrations
8+
9+ from gallery .thumbnails import resize_photo
10+
11+ if TYPE_CHECKING :
12+ from gallery .models import Photo
13+
14+
15+ def migrate_photos (apps , schema_editor ):
16+ Photo : "Photo" = apps .get_model ("gallery" , "Photo" )
17+
18+ for photo in Photo .objects .all ():
19+ image_path = Path (photo .image .path )
20+ if not image_path .exists ():
21+ photo .delete ()
22+ continue
23+
24+ photo .image .save (image_path .name , photo .image )
25+ old_dir = image_path .with_suffix ("" )
26+ if old_dir .exists ():
27+ shutil .rmtree (old_dir )
28+
29+ resize_photo (photo )
30+
31+
32+ class Migration (migrations .Migration ):
33+ dependencies = [
34+ ("gallery" , "0004_alter_photo_image" ),
35+ ]
36+
37+ operations = [migrations .RunPython (migrate_photos )]
You can’t perform that action at this time.
0 commit comments