Add justified photo grid layout with lazy loading and image dimensions.

This commit is contained in:
krek0 2026-04-24 21:43:25 +02:00
parent 3efa217716
commit 931c264a44
6 changed files with 179 additions and 4 deletions

View file

@ -0,0 +1,45 @@
import photologue.models
from django.db import migrations, models
def fill_dimensions(apps, schema_editor):
Photo = apps.get_model('photologue', 'Photo')
for photo in Photo.objects.filter(image_width__isnull=True).iterator():
try:
photo.image_width = photo.image.width
photo.image_height = photo.image.height
photo.save(update_fields=['image_width', 'image_height'])
except Exception:
pass
class Migration(migrations.Migration):
dependencies = [
('photologue', '0007_allow_duplicate_photo_titles'),
]
operations = [
migrations.AddField(
model_name='photo',
name='image_width',
field=models.PositiveIntegerField(editable=False, null=True),
),
migrations.AddField(
model_name='photo',
name='image_height',
field=models.PositiveIntegerField(editable=False, null=True),
),
migrations.RunPython(fill_dimensions, migrations.RunPython.noop),
migrations.AlterField(
model_name='photo',
name='image',
field=models.ImageField(
max_length=100,
upload_to=photologue.models.get_storage_path,
verbose_name='image',
width_field='image_width',
height_field='image_height',
),
),
]

View file

@ -0,0 +1,31 @@
from django.db import migrations
def regen_thumbnails(apps, schema_editor):
Photo = apps.get_model("photologue", "Photo")
PhotoSize = apps.get_model("photologue", "PhotoSize")
try:
thumbnail = PhotoSize.objects.get(name="thumbnail")
except PhotoSize.DoesNotExist:
return
for photo in Photo.objects.all():
# Use the real model instance to access file methods
from photologue.models import Photo as RealPhoto
try:
real_photo = RealPhoto.objects.get(pk=photo.pk)
real_photo.remove_size(thumbnail)
except Exception:
pass
class Migration(migrations.Migration):
dependencies = [
("photologue", "0008_photo_dimensions"),
]
operations = [
migrations.RunPython(regen_thumbnails, migrations.RunPython.noop),
]