Add justified photo grid layout with lazy loading and image dimensions.
This commit is contained in:
parent
3efa217716
commit
931c264a44
6 changed files with 179 additions and 4 deletions
45
photologue/migrations/0008_photo_dimensions.py
Normal file
45
photologue/migrations/0008_photo_dimensions.py
Normal 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',
|
||||
),
|
||||
),
|
||||
]
|
||||
Loading…
Add table
Add a link
Reference in a new issue